File tree Expand file tree Collapse file tree 3 files changed +22
-20
lines changed
Expand file tree Collapse file tree 3 files changed +22
-20
lines changed Original file line number Diff line number Diff line change @@ -3725,25 +3725,18 @@ DataFrameTest >> testReplaceNilsWithMedian [
37253725{ #category : #replacing }
37263726DataFrameTest >> testReplaceNilsWithMode [
37273727
3728- |expected |
3729-
3730- df := DataFrame withRows: #(
3731- (7 1 nil)
3732- (8 nil nil )
3733- (nil 1 43 )).
3728+ | expected |
3729+ df := DataFrame withRows: #( #( 7 1 nil ) #( 8 nil nil ) #( nil 1 43 ) ).
37343730
3735- df rowNames: #(A B C) .
3736- df columnNames: #(Column1 Column2 Column3) .
3731+ df rowNames: #( A B C ) .
3732+ df columnNames: #( Column1 Column2 Column3 ) .
37373733
3738- expected := DataFrame withRows: #(
3739- (7 1 43)
3740- (8 1 43 )
3741- (7 1 43 )).
3734+ expected := DataFrame withRows: #( #( 7 1 43 ) #( 8 1 43 ) #( 8 1 43 ) ).
37423735
3743- expected rowNames: #(A B C) .
3744- expected columnNames: #(Column1 Column2 Column3) .
3736+ expected rowNames: #( A B C ) .
3737+ expected columnNames: #( Column1 Column2 Column3 ) .
37453738
3746- self assert: ( df replaceNilsWithMode) equals: expected
3739+ self assert: df replaceNilsWithMode equals: expected
37473740]
37483741
37493742{ #category : #replacing }
Original file line number Diff line number Diff line change @@ -1645,13 +1645,11 @@ DataFrame >> replaceNilsWithMedian [
16451645{ #category : #replacing }
16461646DataFrame >> replaceNilsWithMode [
16471647
1648- | modeOfColumn |
16491648 1 to: self numberOfColumns do: [ :i |
1650- modeOfColumn := (( self columnAt: i) select: [ :ele | ele isNotNil ]) mode.
1649+ | modeOfColumn |
16511650 1 to: self numberOfRows do: [ :j |
1652- (self at: j at: i) ifNil: [
1653- self at: j at: i put: modeOfColumn ] ].
1654- ]
1651+ (self at: j at: i) ifNil: [ self at: j at: i put: (modeOfColumn ifNil: [ modeOfColumn := ((self columnAt: i) select: [ :ele | ele isNotNil ]) mode ]) ] ].
1652+ modeOfColumn := nil ]
16551653]
16561654
16571655{ #category : #replacing }
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ DataSeries class >> newFrom: aCollection [
2121 ifFalse: [ aCollection withIndexCollect: [ :each :i | i - > each ] ])
2222]
2323
24+ { #category : #' instance creation' }
25+ DataSeries class >> newFromKeys: keys andValues: values [
26+
27+ | dict |
28+ self flag: #pharo12 . " This is a copy of the superclass with a speed up. I'll propose this speedup in Pharo 12 so when Pharo 12 will be the minimal suuported version then we can drop this method."
29+ dict := self new : keys size.
30+ keys with: values do: [ :k :v | dict at: k put: v ].
31+ ^ dict
32+ ]
33+
2434{ #category : #' instance creation' }
2535DataSeries class >> withKeys: keys values: values [
2636 ^ self newFromKeys: keys andValues: values
@@ -450,6 +460,7 @@ DataSeries >> makeNumerical [
450460
451461{ #category : #accessing }
452462DataSeries >> mode [
463+
453464 | valueCounts maxCount |
454465 valueCounts := self valueCounts.
455466 maxCount := valueCounts max.
You can’t perform that action at this time.
0 commit comments