diff --git a/src/DataFrame-Tests/DataFrameTest.class.st b/src/DataFrame-Tests/DataFrameTest.class.st index f45dc9fb..c7fc717e 100644 --- a/src/DataFrame-Tests/DataFrameTest.class.st +++ b/src/DataFrame-Tests/DataFrameTest.class.st @@ -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 [ diff --git a/src/DataFrame/Collection.extension.st b/src/DataFrame/Collection.extension.st index 30df4bf0..45ac22fe 100644 --- a/src/DataFrame/Collection.extension.st +++ b/src/DataFrame/Collection.extension.st @@ -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. @@ -31,6 +32,36 @@ Collection >> asDataFrame [ ^ dataFrame ] +{ #category : #'*DataFrame' } +Collection >> asDataFrameWithColumnNames: arrayOfColumnNames [ + "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 [