Skip to content

Commit 39f003e

Browse files
Added countNils and countNonNils methods for the DataSeries class along with tests.
1 parent a558805 commit 39f003e

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/DataFrame-Tests/DataSeriesTest.class.st

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,32 @@ DataSeriesTest >> testCopyChangeDoesNotAffectOriginal [
10581058
self assert: original equals: expectedOriginalAfterChange
10591059
]
10601060

1061+
{ #category : #'tests - statistics' }
1062+
DataSeriesTest >> testCountNils [
1063+
1064+
| seriesWithNils |
1065+
keyArray := #( a b c d e f g h i j k ).
1066+
1067+
seriesWithNils := DataSeries
1068+
withKeys: keyArray
1069+
values: #( 3 7 6 20 nil 9 nil 10 15 13 nil )
1070+
name: 'ExampleSeries'.
1071+
self assert: seriesWithNils countNils equals: 3
1072+
]
1073+
1074+
{ #category : #'tests - statistics' }
1075+
DataSeriesTest >> testCountNonNils [
1076+
1077+
| seriesWithNils |
1078+
keyArray := #( a b c d e f g h i j k ).
1079+
1080+
seriesWithNils := DataSeries
1081+
withKeys: keyArray
1082+
values: #( 3 7 6 20 nil 9 nil 10 15 13 nil )
1083+
name: 'ExampleSeries'.
1084+
self assert: seriesWithNils countNonNils equals: 8
1085+
]
1086+
10611087
{ #category : #'tests - creation' }
10621088
DataSeriesTest >> testCreateDataSeriesAsDataSeries [
10631089

src/DataFrame/DataSeries.class.st

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ DataSeries >> correlationWith: otherSeries using: aCorrelationCoefficient [
236236
^ aCorrelationCoefficient between: self and: otherSeries
237237
]
238238

239+
{ #category : #statistics }
240+
DataSeries >> countNils [
241+
"Returns the number of nil values in the data series"
242+
243+
^ self count: [ :each | each isNil ]
244+
]
245+
246+
{ #category : #statistics }
247+
DataSeries >> countNonNils [
248+
"Returns the number of non-nil values in the data series"
249+
250+
^ self count: [ :each | each isNotNil ]
251+
]
252+
239253
{ #category : #statistics }
240254
DataSeries >> crossTabulateWith: aSeries [
241255
"A DataFrame is returned which is useful in quantitatively analyzing the relationship of values in one data series with the values in another data series"

0 commit comments

Comments
 (0)