Skip to content

Commit 36c0525

Browse files
committed
Allow arithmetic operations with nils in data series
If a nil is present, we will keep a nil in the result.
1 parent c8d2feb commit 36c0525

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/DataFrame-Tests/DataSeriesTest.class.st

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ DataSeriesTest >> testArithmeticsDivideSeriesBySeriesSameKeysDifferentName [
188188
self assert: actual equals: expected
189189
]
190190

191+
{ #category : #'as yet unclassified' }
192+
DataSeriesTest >> testArithmeticsDivideSeriesBySeriesWithNils [
193+
194+
| a b c |
195+
a := #( 2 4 nil ) asDataSeries.
196+
b := #( 1 nil 3 ) asDataSeries.
197+
c := #( 2 nil nil ) asDataSeries.
198+
199+
self assert: a / b equals: c
200+
]
201+
191202
{ #category : #arithmetic }
192203
DataSeriesTest >> testArithmeticsMultiplyArrayBySeries [
193204

src/DataFrame/DataSeries.class.st

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ DataSeries >> adaptToCollection: rcvr andSend: selector [
9292
"If I am involved in arithmetic with another Collection, return a Collection of
9393
the results of each element combined with the scalar in that expression."
9494

95-
(rcvr isSequenceable and: [ self isSequenceable ]) ifFalse:
96-
[self error: 'Only sequenceable collections may be combined arithmetically'].
97-
^ rcvr withSeries: self collect:
98-
[:rcvrElement :myElement | rcvrElement perform: selector with: myElement]
95+
(rcvr isSequenceable and: [ self isSequenceable ]) ifFalse: [ self error: 'Only sequenceable collections may be combined arithmetically' ].
96+
97+
98+
^ rcvr withSeries: self collect: [ :rcvrElement :myElement |
99+
(rcvrElement isNil or: [ myElement isNil ])
100+
ifTrue: [ nil ]
101+
ifFalse: [ rcvrElement perform: selector with: myElement ] ]
99102
]
100103

101104
{ #category : #converting }

0 commit comments

Comments
 (0)