Skip to content

Added methods to convert collections to dataframes with specific row and column names #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/DataFrame-Tests/DataFrameTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,62 @@ DataFrameTest >> testAsDataFrameEmptyColumns [
self assert: actual equals: expected
]

{ #category : #tests }
DataFrameTest >> testAsDataFrameWithColumnNames [

| actual expected |
actual := #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
asDataFrameWithColumnNames: #( a b c ).
expected := DataFrame
withRows: #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
columnNames: #( a b c ).

self assert: actual equals: expected
]

{ #category : #tests }
DataFrameTest >> testAsDataFrameWithColumnNamesWithRowNames [

| actual expected |
actual := #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
asDataFrameWithColumnNames: #( a b c )
withRowNames: #( d e f ).
expected := DataFrame
withRows: #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
rowNames: #( d e f )
columnNames: #( a b c ).

self assert: actual equals: expected
]

{ #category : #tests }
DataFrameTest >> testAsDataFrameWithRowNames [

| actual expected |
actual := #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
asDataFrameWithRowNames: #( a b c ).
expected := DataFrame
withRows: #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
rowNames: #( a b c ).

self assert: actual equals: expected
]

{ #category : #tests }
DataFrameTest >> testAsDataFrameWithRowNamesWithColumnNames [

| actual expected |
actual := #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
asDataFrameWithRowNames: #( a b c )
withColumnNames: #( d e f ).
expected := DataFrame
withRows: #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) )
rowNames: #( a b c )
columnNames: #( d e f ).

self assert: actual equals: expected
]

{ #category : #tests }
DataFrameTest >> testAsDataFrameWithUnevenRowElements [

Expand Down
31 changes: 31 additions & 0 deletions src/DataFrame/Collection.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Collection >> ** arg [

{ #category : #'*DataFrame' }
Collection >> asDataFrame [
"Answer a DataFrame whose elements are the elements of the receiver."

| numberOfRows numberOfColumns dataFrame |
numberOfRows := self size.
Expand All @@ -31,6 +32,36 @@ Collection >> asDataFrame [
^ dataFrame
]

{ #category : #'*DataFrame' }
Collection >> asDataFrameWithColumnNames: arrayOfColumnNames [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say with Oleks thta this was maybe too much and that we could just do coll asDataFrame columnNames: coll2?

I'm not really against it but I don't know if this has much value.

Maybe @olekscode has an opinion

"Answer a DataFrame whose elements are the elements of the receiver and column names are the contents of the collection arrayOfColumnNames."

^ self asDataFrame columnNames: arrayOfColumnNames
]

{ #category : #'*DataFrame' }
Collection >> asDataFrameWithColumnNames: arrayOfColumnNames withRowNames: arrayOfRowNames [
"Answer a DataFrame whose elements are the elements of the receiver, column names are the contents of the collection arrayOfColumnNames and row names are the contents of the collection arrayOfRowNames."

^ (self asDataFrame columnNames: arrayOfColumnNames) rowNames:
arrayOfRowNames
]

{ #category : #'*DataFrame' }
Collection >> asDataFrameWithRowNames: arrayOfRowNames [
"Answer a DataFrame whose elements are the elements of the receiver and row names are the contents of the collection arrayOfRowNames."

^ self asDataFrame rowNames: arrayOfRowNames
]

{ #category : #'*DataFrame' }
Collection >> asDataFrameWithRowNames: arrayOfRowNames withColumnNames: arrayOfColumnNames [
"Answer a DataFrame whose elements are the elements of the receiver, row names are the contents of the collection arrayOfRowNames and column names are the contents of the collection arrayOfColumnNames."

^ (self asDataFrame rowNames: arrayOfRowNames) columnNames:
arrayOfColumnNames
]

{ #category : #'*DataFrame-Core-Base' }
Collection >> asDataSeries [

Expand Down