Skip to content
Merged
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
213 changes: 213 additions & 0 deletions src/DataFrame-Tests/DataFrameTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,41 @@ DataFrameTest >> testColumnsAt [
self assert: actualDataFrame equals: expectedDataFrame.
]

{ #category : #tests }
DataFrameTest >> testColumnsAtPut [
| rowNames columnNames dataFrame newColumns expected |

rowNames := #('01:10' '01:30' '01:50' '02:10' '02:30') collect: #asTime.
columnNames := #(temperature precipitation type).

dataFrame := DataFrame
withRows: #(
(2.4 true rain)
(0.5 true rain)
(-1.2 true snow)
(-2.3 false -)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

newColumns := #(
(1 1 1 1 1)
(2 2 2 2 2)).

expected := DataFrame
withRows: #(
(2 true 1)
(2 true 1)
(2 true 1)
(2 false 1)
(2 true 1))
rowNames: rowNames
columnNames: columnNames.

dataFrame columnsAt: #(3 1) put: newColumns.
self assert: dataFrame equals: expected.
]

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

Expand All @@ -555,6 +590,76 @@ DataFrameTest >> testColumnsFromTo [
self assert: actualDataFrame equals: expectedDataFrame.
]

{ #category : #tests }
DataFrameTest >> testColumnsFromToPut [
| rowNames columnNames dataFrame newColumns expected |

rowNames := #('01:10' '01:30' '01:50' '02:10' '02:30') collect: #asTime.
columnNames := #(temperature precipitation type).

dataFrame := DataFrame
withRows: #(
(2.4 true rain)
(0.5 true rain)
(-1.2 true snow)
(-2.3 false -)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

newColumns := #(
(1 1 1 1 1)
(2 2 2 2 2)).

expected := DataFrame
withRows: #(
(2.4 2 1)
(0.5 2 1)
(-1.2 2 1)
(-2.3 2 1)
(3.2 2 1))
rowNames: rowNames
columnNames: columnNames.

dataFrame columnsFrom: 3 to: 2 put: newColumns.
self assert: dataFrame equals: expected.
]

{ #category : #tests }
DataFrameTest >> testColumnsPut [
| rowNames columnNames dataFrame newColumns expected |

rowNames := #('01:10' '01:30' '01:50' '02:10' '02:30') collect: #asTime.
columnNames := #(temperature precipitation type).

dataFrame := DataFrame
withRows: #(
(2.4 true rain)
(0.5 true rain)
(-1.2 true snow)
(-2.3 false -)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

newColumns := #(
(1 1 1 1 1)
(2 2 2 2 2)).

expected := DataFrame
withRows: #(
(2 true 1)
(2 true 1)
(2 true 1)
(2 false 1)
(2 true 1))
rowNames: rowNames
columnNames: columnNames.

dataFrame columns: #(type temperature) put: newColumns.
self assert: dataFrame equals: expected.
]

{ #category : #tests }
DataFrameTest >> testCreateDataFrameWith3ColumnsAndNoRows [
| dataFrame |
Expand Down Expand Up @@ -1189,6 +1294,42 @@ DataFrameTest >> testRowsAt [
self assert: actualDataFrame equals: expectedDataFrame.
]

{ #category : #tests }
DataFrameTest >> testRowsAtPut [
| rowNames columnNames dataFrame newRows expected |

rowNames := #('01:10' '01:30' '01:50' '02:10' '02:30') collect: #asTime.
columnNames := #(temperature precipitation type).

dataFrame := DataFrame
withRows: #(
(2.4 true rain)
(0.5 true rain)
(-1.2 true snow)
(-2.3 false -)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

newRows := #(
(1 1 1)
(2 2 2)
(3 3 3)).

expected := DataFrame
withRows: #(
(2.4 true rain)
(3 3 3)
(1 1 1)
(-2.3 false -)
(2 2 2))
rowNames: rowNames
columnNames: columnNames.

dataFrame rowsAt: #(3 5 2) put: newRows.
self assert: dataFrame equals: expected.
]

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

Expand All @@ -1206,6 +1347,78 @@ DataFrameTest >> testRowsFromTo [
self assert: actualDataFrame equals: expectedDataFrame.
]

{ #category : #tests }
DataFrameTest >> testRowsFromToPut [
| rowNames columnNames dataFrame newRows expected |

rowNames := #('01:10' '01:30' '01:50' '02:10' '02:30') collect: #asTime.
columnNames := #(temperature precipitation type).

dataFrame := DataFrame
withRows: #(
(2.4 true rain)
(0.5 true rain)
(-1.2 true snow)
(-2.3 false -)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

newRows := #(
(1 1 1)
(2 2 2)
(3 3 3)).

expected := DataFrame
withRows: #(
(2.4 true rain)
(3 3 3)
(2 2 2)
(1 1 1)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

dataFrame rowsFrom: 4 to: 2 put: newRows.
self assert: dataFrame equals: expected.
]

{ #category : #tests }
DataFrameTest >> testRowsPut [
| rowNames columnNames dataFrame newRows expected |

rowNames := #('01:10' '01:30' '01:50' '02:10' '02:30') collect: #asTime.
columnNames := #(temperature precipitation type).

dataFrame := DataFrame
withRows: #(
(2.4 true rain)
(0.5 true rain)
(-1.2 true snow)
(-2.3 false -)
(3.2 true rain))
rowNames: rowNames
columnNames: columnNames.

newRows := #(
(1 1 1)
(2 2 2)
(3 3 3)).

expected := DataFrame
withRows: #(
(2.4 true rain)
(3 3 3)
(1 1 1)
(-2.3 false -)
(2 2 2))
rowNames: rowNames
columnNames: columnNames.

dataFrame rows: { '01:50' asTime . '02:30' asTime . '01:30' asTime } put: newRows.
self assert: dataFrame equals: expected.
]

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

Expand Down
72 changes: 72 additions & 0 deletions src/DataFrame/DataFrame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ DataFrame >> columns: anArrayOfNames [
^ self columnsAt: anArrayOfNumbers.
]

{ #category : #accessing }
DataFrame >> columns: anArrayOfColumnNames put: anArrayOfArrays [

anArrayOfArrays size = anArrayOfColumnNames size
ifFalse: [ SizeMismatch signal ].

anArrayOfColumnNames with: anArrayOfArrays do: [ :name :array |
self column: name put: array ].
]

{ #category : #accessing }
DataFrame >> columnsAt: anArrayOfNumbers [

Expand All @@ -567,6 +577,16 @@ DataFrame >> columnsAt: anArrayOfNumbers [
columnNames: newColumnNames.
]

{ #category : #accessing }
DataFrame >> columnsAt: anArrayOfNumbers put: anArrayOfArrays [

anArrayOfArrays size = anArrayOfNumbers size
ifFalse: [ SizeMismatch signal ].

anArrayOfNumbers with: anArrayOfArrays do: [ :index :array |
self columnAt: index put: array ].
]

{ #category : #accessing }
DataFrame >> columnsFrom: begin to: end [

Expand All @@ -579,6 +599,22 @@ DataFrame >> columnsFrom: begin to: end [
^ self columnsAt: array.
]

{ #category : #accessing }
DataFrame >> columnsFrom: firstNumber to: secondNumber put: anArrayOfArrays [

| interval |

anArrayOfArrays size = ((firstNumber - secondNumber) abs + 1)
ifFalse: [ SizeMismatch signal ].

interval := secondNumber >= firstNumber
ifTrue: [ (firstNumber to: secondNumber) ]
ifFalse: [ (secondNumber to: firstNumber) reversed ].

interval withIndexDo: [ :columnIndex :i |
self columnAt: columnIndex put: (anArrayOfArrays at: i) ].
]

{ #category : #accessing }
DataFrame >> contents [

Expand Down Expand Up @@ -931,6 +967,16 @@ DataFrame >> rows: anArrayOfNames [
^ self rowsAt: anArrayOfNumbers.
]

{ #category : #accessing }
DataFrame >> rows: anArrayOfRowNames put: anArrayOfArrays [

anArrayOfArrays size = anArrayOfRowNames size
ifFalse: [ SizeMismatch signal ].

anArrayOfRowNames with: anArrayOfArrays do: [ :name :array |
self row: name put: array ].
]

{ #category : #accessing }
DataFrame >> rowsAt: anArrayOfNumbers [

Expand All @@ -945,12 +991,38 @@ DataFrame >> rowsAt: anArrayOfNumbers [
columnNames: self columnNames.
]

{ #category : #accessing }
DataFrame >> rowsAt: anArrayOfNumbers put: anArrayOfArrays [

anArrayOfArrays size = anArrayOfNumbers size
ifFalse: [ SizeMismatch signal ].

anArrayOfNumbers with: anArrayOfArrays do: [ :index :array |
self rowAt: index put: array ].
]

{ #category : #accessing }
DataFrame >> rowsFrom: begin to: end [

^ self rowsAt: (begin to: end).
]

{ #category : #accessing }
DataFrame >> rowsFrom: firstNumber to: secondNumber put: anArrayOfArrays [

| interval |

anArrayOfArrays size = ((firstNumber - secondNumber) abs + 1)
ifFalse: [ SizeMismatch signal ].

interval := secondNumber >= firstNumber
ifTrue: [ (firstNumber to: secondNumber) ]
ifFalse: [ (secondNumber to: firstNumber) reversed ].

interval withIndexDo: [ :rowIndex :i |
self rowAt: rowIndex put: (anArrayOfArrays at: i) ].
]

{ #category : #enumerating }
DataFrame >> select: aBlock [
"Evaluate aBlock with each of the receiver's elements as the argument.
Expand Down