Skip to content

Commit fda2c19

Browse files
Optimized and wrote regression tests for #hasNils. Also made the code readable
1 parent 6b70260 commit fda2c19

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,19 +1617,39 @@ DataFrameTest >> testFindAllIndicesOfAtColumnFloat [
16171617
{ #category : #replacing }
16181618
DataFrameTest >> testHasNils [
16191619

1620-
| df1 df2 |
1621-
df1 := DataFrame withRows: #( #( nil 1.609 true ) #( Dubai 2.789 nil ) #( nil 8.788 false ) ).
1620+
| df1 df2 df3 df4 |
1621+
df1 := DataFrame withRows:
1622+
#( #( nil 1.609 true ) #( Dubai 2.789 nil )
1623+
#( nil 8.788 false ) ).
16221624
df1 rowNames: #( A B C ).
16231625
df1 columnNames: #( City Population BeenThere ).
16241626

16251627
self assert: df1 hasNils.
16261628

1627-
df2 := DataFrame withRows: #( #( Barcelona 1.609 true ) #( Dubai 2.789 true ) #( London 8.788 false ) ).
1629+
df2 := DataFrame withRows:
1630+
#( #( Barcelona 1.609 true ) #( Dubai 2.789 true )
1631+
#( London 8.788 false ) ).
16281632

16291633
df2 rowNames: #( A B C ).
16301634
df2 columnNames: #( City Population BeenThere ).
16311635

1632-
self deny: df2 hasNils
1636+
self deny: df2 hasNils.
1637+
1638+
df3 := DataFrame withRows:
1639+
#( #( Barcelona 1.609 true ) #( Dubai 2.789 nil )
1640+
#( London 8.788 false ) ).
1641+
df3 rowNames: #( A B C ).
1642+
df3 columnNames: #( City Population BeenThere ).
1643+
1644+
self assert: df3 hasNils.
1645+
1646+
df4 := DataFrame withRows:
1647+
#( #( Barcelona nil true ) #( Dubai 2.789 true )
1648+
#( London 8.788 false ) ).
1649+
df4 rowNames: #( A B C ).
1650+
df4 columnNames: #( City Population BeenThere ).
1651+
1652+
self assert: df4 hasNils
16331653
]
16341654

16351655
{ #category : #replacing }

src/DataFrame/DataFrame.class.st

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,12 @@ DataFrame >> groupBy: columnName aggregate: anArrayOfUsingAsStatements [
10081008
{ #category : #replacing }
10091009
DataFrame >> hasNils [
10101010
"Returns true if there is atleast one nil value in the data frame. Returns false if there are no nil values in the dataframe"
1011-
1012-
1 to: self numberOfColumns do: [ :each |
1013-
(self columnAt: each) hasNil
1014-
ifTrue:[^ true] ].
1011+
1012+
| arrayOfColumns |
1013+
arrayOfColumns := self columns.
1014+
1 to: self numberOfColumns do: [ :column |
1015+
1 to: self numberOfRows do: [ :row |
1016+
((arrayOfColumns at: column) at: row) ifNil: [ ^ true ] ] ].
10151017
^ false
10161018
]
10171019

0 commit comments

Comments
 (0)