File tree Expand file tree Collapse file tree 3 files changed +12
-20
lines changed
Expand file tree Collapse file tree 3 files changed +12
-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 @@ -460,6 +460,7 @@ DataSeries >> makeNumerical [
460460
461461{ #category : #accessing }
462462DataSeries >> mode [
463+
463464 | valueCounts maxCount |
464465 valueCounts := self valueCounts.
465466 maxCount := valueCounts max.
You can’t perform that action at this time.
0 commit comments