Skip to content

Commit fc16dc7

Browse files
authored
Merge pull request #240 from olekscode/239-Add-argmax-to-DataSeries
Fixed #239. Implemented argmin and argmax for DataSeries
2 parents 43fde11 + 8065af1 commit fc16dc7

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/DataFrame-Tests/DataSeriesTest.class.st

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,54 @@ DataSeriesTest >> setUp [
1717
series := DataSeries withKeys: keyArray values: #( 3 7 6 20 8 9 8 10 15 13 16 ) name: 'ExampleSeries'
1818
]
1919

20+
{ #category : #'tests - statistics' }
21+
DataSeriesTest >> testArgmax [
22+
23+
| records |
24+
25+
records := DataSeries
26+
withKeys: #(2017 2018 2019 2020)
27+
values: #(13 42 25 15).
28+
29+
self assert: records argmax equals: 2018
30+
]
31+
32+
{ #category : #'tests - statistics' }
33+
DataSeriesTest >> testArgmaxWithNils [
34+
35+
| records |
36+
37+
records := DataSeries
38+
withKeys: #(2017 2018 2019 2020)
39+
values: #(13 nil 25 15).
40+
41+
self assert: records argmax equals: 2019
42+
]
43+
44+
{ #category : #'tests - statistics' }
45+
DataSeriesTest >> testArgmin [
46+
47+
| records |
48+
49+
records := DataSeries
50+
withKeys: #(2017 2018 2019 2020)
51+
values: #(13 42 25 15).
52+
53+
self assert: records argmin equals: 2017
54+
]
55+
56+
{ #category : #'tests - statistics' }
57+
DataSeriesTest >> testArgminWithNils [
58+
59+
| records |
60+
61+
records := DataSeries
62+
withKeys: #(2017 2018 2019 2020)
63+
values: #(nil 42 25 15).
64+
65+
self assert: records argmin equals: 2020
66+
]
67+
2068
{ #category : #'tests - arithmetic' }
2169
DataSeriesTest >> testArithmeticsAddArrayToSeries [
2270

src/DataFrame/DataSeries.class.st

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ DataSeries >> adaptToCollection: rcvr andSend: selector [
111111
ifFalse: [ rcvrElement perform: selector with: myElement ] ]
112112
]
113113

114+
{ #category : #statistics }
115+
DataSeries >> argmax [
116+
"Returns the key which corresponds to the maximum value of the dataseries"
117+
118+
^ self keyAtValue: self max
119+
]
120+
121+
{ #category : #statistics }
122+
DataSeries >> argmin [
123+
"Returns the key which corresponds to the minimum value of the dataseries"
124+
125+
^ self keyAtValue: self min
126+
]
127+
114128
{ #category : #converting }
115129
DataSeries >> asDataFrame [
116130
"Converts a data series to a data frame with 1 column. The values in the column of the data frame are the values of the data series. The row names of this data frame are the keys of the data series. The column name of the data frame is same as the name of the data series"

0 commit comments

Comments
 (0)