Skip to content

Commit

Permalink
Add drop column method and test.
Browse files Browse the repository at this point in the history
Add test for shuffling a data frame
  • Loading branch information
Hernán Morales Durand committed Dec 13, 2023
1 parent 56d9923 commit 4878ce3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/DataFrame-Tests/DataFrameTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,19 @@ DataFrameTest >> testColumns [
self assert: df columns equals: expectedCollection
]

{ #category : 'tests' }
DataFrameTest >> testColumnsAllBut [

| expectedDataFrame |
expectedDataFrame := DataFrame withRows: #( #( 'Barcelona' 1.609 ) #( 'Dubai' 2.789 ) #( 'London' 8.788 ) ).
expectedDataFrame rowNames: #( 'A' 'B' 'C' ).
expectedDataFrame columnNames: #( 'City' 'Population').

self
assert: (df columnsAllBut: #(BeenThere))
equals: expectedDataFrame
]

{ #category : 'tests' }
DataFrameTest >> testColumnsAt [

Expand Down Expand Up @@ -5171,22 +5184,24 @@ DataFrameTest >> testShuffledWithSeed [

| expected |

"df = A Barcelona B Dubai C London"
expected := DataFrame withRows: #(
('Barcelona' 1.609 true)
('London' 8.788 false)
('Dubai' 2.789 true)).
expected rowNames: #( 'A' 'C' 'B').
expected columnNames: #( 'City' 'Population' 'BeenThere' ).

self assert: (df shuffleWithSeed: 1) equals: expected.

self assert: (df shuffleWithSeed: 2) equals: expected.

expected := DataFrame withRows: #(
('London' 8.788 false)
('Barcelona' 1.609 true)
('Dubai' 2.789 true)).
('Dubai' 2.789 true)
('Barcelona' 1.609 true)
('London' 8.788 false) ).
expected rowNames: #('B' 'A' 'C').
expected columnNames: #( 'City' 'Population' 'BeenThere' ).
self assert: (df shuffleWithSeed: 2) equals: expected.

self assert: (df shuffleWithSeed: 3) equals: expected.

]

{ #category : 'tests' }
Expand Down
13 changes: 13 additions & 0 deletions src/DataFrame/DataFrame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,13 @@ DataFrame >> columns: anArrayOfColumnNames put: anArrayOfArrays [
self column: name put: array ]
]

{ #category : 'accessing' }
DataFrame >> columnsAllBut: aCollectionOfColumnNames [
"Returns a <Collection> of except those present in aCollectionOfColumnNames"

^ self columns: (self columnNames copyWithoutAll: aCollectionOfColumnNames)
]

{ #category : 'accessing' }
DataFrame >> columnsAt: anArrayOfNumbers [
"Returns a collection of columns whose column indices are present in the array anArrayOfNumbers"
Expand Down Expand Up @@ -2441,6 +2448,12 @@ DataFrame >> shuffleWithSeed: aNumber [
^ self shuffleBy: (Random new seed: aNumber)
]

{ #category : 'accessing' }
DataFrame >> shuffled [

self shuffleBy: Random new
]

{ #category : 'accessing' }
DataFrame >> size [
"Returns the number of rows of a DataFrame"
Expand Down

0 comments on commit 4878ce3

Please sign in to comment.