Skip to content

Commit f3527f5

Browse files
Statistical methods such as stdev, max and min can now handle nils.
1 parent 483c533 commit f3527f5

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/DataFrame-Tests/DataSeriesTest.class.st

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,30 @@ DataSeriesTest >> testMathTan [
15881588
self assert: a tan closeTo: b
15891589
]
15901590

1591+
{ #category : #'tests - statistics' }
1592+
DataSeriesTest >> testMax [
1593+
1594+
self assert: #( 1 2 3 4 ) asDataSeries max equals: 4
1595+
]
1596+
1597+
{ #category : #'tests - statistics' }
1598+
DataSeriesTest >> testMaxWithNils [
1599+
1600+
self assert: #( 1 nil 3 nil ) asDataSeries max equals: 3
1601+
]
1602+
1603+
{ #category : #'tests - statistics' }
1604+
DataSeriesTest >> testMin [
1605+
1606+
self assert: #( 1 2 3 4 ) asDataSeries min equals: 1
1607+
]
1608+
1609+
{ #category : #'tests - statistics' }
1610+
DataSeriesTest >> testMinWithNils [
1611+
1612+
self assert: #( nil 2 nil 4 ) asDataSeries min equals: 2
1613+
]
1614+
15911615
{ #category : #'tests - creation' }
15921616
DataSeriesTest >> testNewFrom [
15931617

@@ -2176,6 +2200,18 @@ DataSeriesTest >> testStatsZerothQuartileEqualsMin [
21762200
self assert: series zerothQuartile equals: series min
21772201
]
21782202

2203+
{ #category : #'tests - statistics' }
2204+
DataSeriesTest >> testStdev [
2205+
2206+
self assert: #( 1 2 3 ) asDataSeries stdev equals: 1
2207+
]
2208+
2209+
{ #category : #tests }
2210+
DataSeriesTest >> testStdevWithNils [
2211+
2212+
self assert: #( 1 nil 2 nil 3 ) asDataSeries stdev equals: 1
2213+
]
2214+
21792215
{ #category : #'tests - arithmetic' }
21802216
DataSeriesTest >> testSum [
21812217

src/DataFrame/DataSeries.class.st

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,20 @@ DataSeries >> makeNumerical [
520520
forcedIsNumerical := true
521521
]
522522

523+
{ #category : #statistics }
524+
DataSeries >> max [
525+
"Returns the maximum value of the dataseries without including nils"
526+
527+
^ (self values reject: #isNil) max
528+
]
529+
530+
{ #category : #statistics }
531+
DataSeries >> min [
532+
"Returns the minimum value of the dataseries without including nils"
533+
534+
^ (self values reject: #isNil) min
535+
]
536+
523537
{ #category : #accessing }
524538
DataSeries >> mode [
525539
"The mode of a set of values is the value that appears most often. "
@@ -757,6 +771,13 @@ DataSeries >> sortedDescending [
757771
^ self sorted: [ :a :b | a > b ]
758772
]
759773

774+
{ #category : #statistics }
775+
DataSeries >> stdev [
776+
"Returns the standard deviation of the dataseries without including nils"
777+
778+
^ (self values reject: #isNil) stdev
779+
]
780+
760781
{ #category : #transformation }
761782
DataSeries >> sum [
762783
"Return the sum of the values over the requested axis. Nil values are excluded."

0 commit comments

Comments
 (0)