Skip to content

Commit 5cbef10

Browse files
committed
Fix test + speedup another method
1 parent 75a7788 commit 5cbef10

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,25 +3725,18 @@ DataFrameTest >> testReplaceNilsWithMedian [
37253725
{ #category : #replacing }
37263726
DataFrameTest >> 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 }

src/DataFrame/DataFrame.class.st

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,13 +1645,11 @@ DataFrame >> replaceNilsWithMedian [
16451645
{ #category : #replacing }
16461646
DataFrame >> 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 }

src/DataFrame/DataSeries.class.st

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ DataSeries >> makeNumerical [
460460

461461
{ #category : #accessing }
462462
DataSeries >> mode [
463+
463464
| valueCounts maxCount |
464465
valueCounts := self valueCounts.
465466
maxCount := valueCounts max.

0 commit comments

Comments
 (0)