Skip to content

Commit 9ec5356

Browse files
committed
Wrote tests for queries
1 parent 0b874f4 commit 9ec5356

File tree

9 files changed

+83
-3
lines changed

9 files changed

+83
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
comparing
2+
closeTo: aDataFrame
3+
4+
aDataFrame species = self species
5+
ifFalse: [ ^ false ].
6+
7+
aDataFrame dimensions = self dimensions
8+
ifFalse: [ ^ false ].
9+
10+
aDataFrame columnTypes = self columnTypes
11+
ifFalse: [ ^ false ].
12+
13+
(aDataFrame rowNames = self rowNames
14+
and: [ aDataFrame columnNames = self columnNames ])
15+
ifFalse: [ ^ false ].
16+
17+
1 to: self numberOfRows do: [ :i |
18+
1 to: self numberOfColumns do: [ :j |
19+
((self at: i at: j) closeTo: (aDataFrame at: i at: j))
20+
ifFalse: [ ^ false ] ] ].
21+
22+
^ true

DataFrame-Core.package/DataFrame.class/instance/select..st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ select: aBlock
1616
(selectedRowNumbers size @ self numberOfColumns).
1717

1818
df rowNames: (selectedRowNumbers collect: [ :i |
19-
self rowNames at: i ]).
19+
self rowNames at: i ]) asArray.
2020

2121
df columnNames: self columnNames.
2222

DataFrame-Tests.package/DataFrameQueriesTests.class/README.md

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
initialization
2+
setUp
3+
4+
df := DataFrame loadIris
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
initialization
2+
testSelectAllWhere
3+
4+
| actual |
5+
6+
actual := df selectAllWhere: [ :species :sepal_width |
7+
species = #setosa and: sepal_width = 3 ].
8+
9+
self assert: actual columnNames equals: df columnNames.
10+
self assert: actual rowNames equals: #(2 13 14 26 39 46).
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
initialization
2+
testSelectWhere
3+
4+
| selectedCols actual |
5+
6+
selectedCols := #(petal_width petal_length).
7+
8+
actual := df
9+
select: selectedCols
10+
where: [ :species :sepal_width |
11+
species = #setosa and: sepal_width = 3 ].
12+
13+
self assert: actual columnNames equals: selectedCols.
14+
self assert: actual rowNames equals: #(2 13 14 26 39 46).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
initialization
2+
testSelectWhereGroupbyAggregate
3+
4+
| selectedCols actual expected |
5+
6+
selectedCols := #(petal_width petal_length).
7+
8+
actual := df select: #(sepal_length species)
9+
where: [ :petal_length :petal_width |
10+
(petal_length < 4.9 and: petal_length > 1.6) and:
11+
(petal_width < 0.4 or: petal_width > 1.5) ]
12+
groupBy: #species
13+
aggregate: #sum.
14+
15+
expected := DataFrame fromColumns: #((15.9 18.2 17.1)).
16+
expected columnNames: #(sepal_length).
17+
expected rowNames: #(setosa versicolor virginica).
18+
19+
self assert: actual closeTo: expected.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"commentStamp" : "",
3+
"super" : "TestCase",
4+
"category" : "DataFrame-Tests",
5+
"classinstvars" : [ ],
6+
"pools" : [ ],
7+
"classvars" : [ ],
8+
"instvars" : [
9+
"df"
10+
],
11+
"name" : "DataFrameQueriesTests",
12+
"type" : "normal"
13+
}

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ Metacello new
2020
load.
2121
```
2222

23-
If you want to contribute to DataFrame library, you will need create a local DataFrame repository and add it to your Iceberg. This can be done automatically by the Metacello script provided above, but first you have to enable Metacello integration for Iceberg. To do that open the Settings Browser using _Ctrl+O+S_ or _World Menu -> System -> Settings_, then click on _Tools -> Software Configuration Management -> Iceberg_, and check the _Enable Metacello integration..._ checkbox. Now all you have to do is run a Metacello script - it will set up the DataFrame repository for you.
24-
2523
### Creating DataSeries
2624
DataSeries can be created from an array of values
2725

0 commit comments

Comments
 (0)