Skip to content

Commit 6859f15

Browse files
committed
Implemented columnAt:put:, rowAt:put: etc.
1 parent 70f919f commit 6859f15

File tree

19 files changed

+200
-10
lines changed

19 files changed

+200
-10
lines changed

DataFrame-Core.package/DataFrame.class/class/fromCSV.separatedBy..st

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ fromCSV: pathToFile separatedBy: separator
1313
df columnNames: (data at: 1) asArray.
1414

1515
"Deduce types"
16-
1 to: (df columnNames size) do: [ :i | | col convertedCol |
16+
"1 to: (df columnNames size) do: [ :i | | col convertedCol |
1717
col := df columnAt: i.
18-
convertedCol := (df columnAt: i) deduceType.
18+
convertedCol := (df columnAt: i) deduceType."
1919

2020
"If a type was deduced"
21-
( col = convertedCol ) ifFalse: [
21+
"( col = convertedCol ) ifFalse: [
2222
1 to: df size do: [ :j |
23-
df at: j at: i put: (convertedCol at: j) ] ] ].
23+
df at: j at: i put: (convertedCol at: j) ] ] ]."
2424

2525
^ df
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
accessing
2+
column: colName put: anArray
3+
4+
| index |
5+
index := self columnNames indexOf: colName.
6+
7+
"If a column with that name does not exist"
8+
index = 0
9+
ifTrue: [ NotFoundError signal ].
10+
11+
^ self columnAt: index put: anArray.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
accessing
2+
columnAt: aNumber put: anArray
3+
4+
anArray size = self numberOfRows
5+
ifFalse: [ SizeMismatch signal ].
6+
7+
contents columnAt: aNumber put: anArray.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
accessing
2+
row: rowName put: anArray
3+
4+
| index |
5+
index := self rowNames indexOf: rowName.
6+
7+
"If a row with that name does not exist"
8+
index = 0
9+
ifTrue: [ NotFoundError signal ].
10+
11+
^ self rowAt: index put: anArray.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
accessing
2+
rowAt: aNumber put: anArray
3+
4+
anArray size = self numberOfColumns
5+
ifFalse: [ SizeMismatch signal ].
6+
7+
contents rowAt: aNumber put: anArray.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
accessing
2+
columnAt: aNumber put: anArray
3+
"Sets all the values of a given column equal to the values in array. It is assumed that array is of the same size as every column (number of rows). This should be tested in DataFrame"
4+
5+
(1 to: self numberOfRows) do: [ :i |
6+
self at: i at: aNumber put: (anArray at: i) ].
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
accessing
2+
rowAt: aNumber put: anArray
3+
"Sets all the values of a given row equal to the values in array. It is assumed that array is of the same size as every row (number of columns). This should be tested in DataFrame"
4+
5+
(1 to: self numberOfColumns) do: [ :j |
6+
self at: aNumber at: j put: (anArray at: j) ].
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
comparing
2+
= otherSeries
3+
4+
"I'm not sure if names should be considered when testing for equality"
5+
self name = otherSeries name
6+
ifFalse: [ ^ false ].
7+
8+
self keys = otherSeries keys
9+
ifFalse: [ ^ false ].
10+
11+
^ super = otherSeries
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests
2+
testColumnAtPut
3+
4+
| actual expected |
5+
6+
expected := DataFrameInternal fromRows: #(
7+
('X' 1.609 0)
8+
('Y' 2.789 1)
9+
('Z' 8.788 0)).
10+
11+
actual := df.
12+
actual columnAt: 1 put: #(X Y Z).
13+
actual columnAt: 3 put: #(0 1 0).
14+
15+
self assert: actual equals: expected.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests
2+
testRowAtPut
3+
4+
| actual expected |
5+
6+
expected := DataFrameInternal fromRows: #(
7+
('Barcelona' 1.609 true)
8+
('X' 'Y' 'Z')
9+
('London' 8.788 false)).
10+
11+
actual := df.
12+
actual rowAt: 2 put: #(X Y Z).
13+
14+
self assert: actual equals: expected.

0 commit comments

Comments
 (0)