Skip to content

Commit d76fb52

Browse files
Added #numericalColumns and #numericalColumnNames along with tests.
1 parent dca6a2a commit d76fb52

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,37 @@ DataFrameTest >> testNumberOfNils [
28252825
self assert: df numberOfNils equals: expected
28262826
]
28272827

2828+
{ #category : #tests }
2829+
DataFrameTest >> testNumericalColumnNames [
2830+
2831+
| dataFrame expected |
2832+
dataFrame := DataFrame withRows:
2833+
#( #( Male 21 Argentina 94 ) #( Female 20 France 97 )
2834+
#( Female 22 Spain 95 ) #( Male 24 Portugal 99 ) ).
2835+
dataFrame columnNames: #( Gender Age Country Score ).
2836+
2837+
expected := #( Age Score ) asOrderedCollection.
2838+
2839+
self assert: dataFrame numericalColumnNames equals: expected
2840+
]
2841+
2842+
{ #category : #tests }
2843+
DataFrameTest >> testNumericalColumns [
2844+
2845+
| dataFrame expected |
2846+
dataFrame := DataFrame withRows:
2847+
#( #( Male 21 Argentina 94 ) #( Female 20 France 97 )
2848+
#( Female 22 Spain 95 ) #( Male 24 Portugal 99 ) ).
2849+
dataFrame columnNames: #( Gender Age Country Score ).
2850+
2851+
expected := DataFrame withRows:
2852+
#( #( 21 94 ) #( 20 97 ) #( 22 95 ) #( 24 99 ) ).
2853+
2854+
expected columnNames: #( Age Score ).
2855+
2856+
self assert: dataFrame numericalColumns equals: expected
2857+
]
2858+
28282859
{ #category : #splitjoin }
28292860
DataFrameTest >> testOuterJoin [
28302861
| df2 expected |

src/DataFrame/DataFrame.class.st

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,21 @@ DataFrame >> numberOfRows [
14281428
^ contents numberOfRows
14291429
]
14301430

1431+
{ #category : #accessing }
1432+
DataFrame >> numericalColumnNames [
1433+
"Returns the names of all numerical columns of the dataframe"
1434+
1435+
^ self columnNames select: [ :columnName |
1436+
(self dataTypes at: columnName) includesBehavior: Number ]
1437+
]
1438+
1439+
{ #category : #accessing }
1440+
DataFrame >> numericalColumns [
1441+
"Returns all numerical columns of the dataframe"
1442+
1443+
^ self columns: self numericalColumnNames
1444+
]
1445+
14311446
{ #category : #splitjoin }
14321447
DataFrame >> outerJoin: aDataFrame [
14331448
"Performs outer join on aDataFrame with rowNames as keys"

0 commit comments

Comments
 (0)