Skip to content

Commit c8d2feb

Browse files
authored
Merge pull request #188 from jecisc/clean-code
Clean code
2 parents 1b76b51 + 40fe98f commit c8d2feb

28 files changed

+2427
-2555
lines changed

src/BaselineOfDataFrame/BaselineOfDataFrame.class.st

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Class {
77
{ #category : #baselines }
88
BaselineOfDataFrame >> baseline: spec [
99
<baseline>
10-
spec for: #common do: [
10+
spec for: #common do: [
1111
"External dependencies"
1212
spec
1313
baseline: 'NeoCSV'
@@ -18,9 +18,9 @@ BaselineOfDataFrame >> baseline: spec [
1818
spec
1919
baseline: 'AINormalization'
2020
with: [ spec repository: 'github://pharo-ai/normalization/src' ].
21-
21+
2222
"Packages"
23-
spec
23+
spec
2424
package: 'DataFrame' with: [ spec requires: #('AINormalization') ];
2525
package: 'DataFrame-Tests' with: [ spec requires: #('DataFrame') ];
2626
package: 'DataFrame-Type' with: [ spec requires: #('DataFrame') ];
@@ -29,17 +29,17 @@ BaselineOfDataFrame >> baseline: spec [
2929
package: 'DataFrame-IO-Tests' with: [ spec requires: #('DataFrame-IO') ];
3030
package: 'DataFrame-Math';
3131
package: 'DataFrame-Math-Tests' with: [ spec requires: #('DataFrame-Math') ] ].
32-
32+
3333
spec
3434
for: #'pharo7.x'
3535
do: [
3636
spec
3737
package: 'DataFrame-Pharo67' ].
38-
38+
3939
spec
4040
for: #'pharo6.x'
4141
do: [
4242
spec
4343
package: 'DataFrame-Pharo6';
44-
package: 'DataFrame-Pharo67' ].
44+
package: 'DataFrame-Pharo67' ]
4545
]

src/DataFrame-IO-Tests/DataFrameCsvReaderTest.class.st

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,85 @@ DataFrameCsvReaderTest >> createFile: aFileReference withContents: aString [
1818
| stream |
1919
stream := aFileReference writeStream.
2020
stream nextPutAll: aString.
21-
stream close.
21+
stream close
2222
]
2323

2424
{ #category : #running }
2525
DataFrameCsvReaderTest >> setUp [
26+
27+
super setUp.
2628
directory := FileSystem memory workingDirectory / 'testData'.
2729
directory createDirectory.
28-
30+
2931
commaCsvFile := directory / 'comma.csv'.
30-
tabCsvFile := directory / 'tab.csv'.
31-
emptyCsvFile := directory / 'empty.csv'.
32-
32+
tabCsvFile := directory / 'tab.csv'.
33+
emptyCsvFile := directory / 'empty.csv'.
34+
3335
self createFile: commaCsvFile withContents: TestCsvStrings commaCsvString.
3436
self createFile: tabCsvFile withContents: TestCsvStrings tabCsvString.
3537
self createFile: emptyCsvFile withContents: TestCsvStrings emptyCsvString.
36-
37-
dataFrameWithRowNames := DataFrame withRows: #(
38-
(2.4 true 'rain')
39-
(0.5 true 'rain')
40-
(-1.2 true 'snow')
41-
(-2.3 false '-')
42-
(3.2 true 'rain')).
43-
44-
dataFrameWithRowNames columnNames: #(temperature precipitation type).
45-
dataFrameWithRowNames rowNames: (#('01:10' '01:30' '01:50' '02:10' '02:30')
46-
collect: #asTime).
47-
38+
39+
dataFrameWithRowNames := DataFrame withRows: #( #( 2.4 true 'rain' ) #( 0.5 true 'rain' ) #( -1.2 true 'snow' ) #( -2.3 false '-' ) #( 3.2 true 'rain' ) ).
40+
41+
dataFrameWithRowNames columnNames: #( temperature precipitation type ).
42+
dataFrameWithRowNames rowNames: (#( '01:10' '01:30' '01:50' '02:10' '02:30' ) collect: #asTime).
43+
4844
dataFrameWithoutRowNames := DataFrame withRows: {
49-
{ '01:10' asTime . 2.4 . true . 'rain' } .
50-
{ '01:30' asTime . 0.5 . true . 'rain' } .
51-
{ '01:50' asTime . -1.2 . true . 'snow' } .
52-
{ '02:10' asTime . -2.3 . false . '-' } .
53-
{ '02:30' asTime . 3.2 . true . 'rain' }}.
54-
55-
dataFrameWithoutRowNames columnNames: #(nil temperature precipitation type).
45+
{
46+
'01:10' asTime.
47+
2.4.
48+
true.
49+
'rain' }.
50+
{
51+
'01:30' asTime.
52+
0.5.
53+
true.
54+
'rain' }.
55+
{
56+
'01:50' asTime.
57+
-1.2.
58+
true.
59+
'snow' }.
60+
{
61+
'02:10' asTime.
62+
-2.3.
63+
false.
64+
'-' }.
65+
{
66+
'02:30' asTime.
67+
3.2.
68+
true.
69+
'rain' } }.
70+
71+
dataFrameWithoutRowNames columnNames: #( nil temperature precipitation type )
5672
]
5773

5874
{ #category : #tests }
5975
DataFrameCsvReaderTest >> testReadCsv [
6076
| actualDataFrame |
6177
actualDataFrame := DataFrame readFromCsv: commaCsvFile.
62-
self assert: actualDataFrame equals: dataFrameWithoutRowNames.
63-
78+
self assert: actualDataFrame equals: dataFrameWithoutRowNames
6479
]
6580

6681
{ #category : #tests }
6782
DataFrameCsvReaderTest >> testReadCsvWithRowNames [
6883
| actualDataFrame |
6984
actualDataFrame := DataFrame readFromCsvWithRowNames: commaCsvFile.
70-
self assert: actualDataFrame equals: dataFrameWithRowNames.
71-
85+
self assert: actualDataFrame equals: dataFrameWithRowNames
7286
]
7387

7488
{ #category : #tests }
7589
DataFrameCsvReaderTest >> testReadCsvWithRowNamesWithSeparatorTab [
7690
| actualDataFrame |
7791
actualDataFrame := DataFrame readFromCsvWithRowNames: tabCsvFile separator: Character tab.
78-
self assert: actualDataFrame equals: dataFrameWithRowNames.
79-
92+
self assert: actualDataFrame equals: dataFrameWithRowNames
8093
]
8194

8295
{ #category : #tests }
8396
DataFrameCsvReaderTest >> testReadCsvWithSeparatorTab [
8497
| actualDataFrame |
8598
actualDataFrame := DataFrame readFromCsv: tabCsvFile withSeparator: Character tab.
86-
self assert: actualDataFrame equals: dataFrameWithoutRowNames.
87-
99+
self assert: actualDataFrame equals: dataFrameWithoutRowNames
88100
]
89101

90102
{ #category : #tests }

src/DataFrame-IO-Tests/DataFrameCsvWriterTest.class.st

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Class {
1010
#category : #'DataFrame-IO-Tests'
1111
}
1212

13-
{ #category : #'as yet unclassified' }
13+
{ #category : #running }
1414
DataFrameCsvWriterTest >> readFile: aFileReference [
1515
| stream contents |
1616
stream := aFileReference readStream.
@@ -21,22 +21,18 @@ DataFrameCsvWriterTest >> readFile: aFileReference [
2121

2222
{ #category : #running }
2323
DataFrameCsvWriterTest >> setUp [
24+
25+
super setUp.
2426
directory := FileSystem memory workingDirectory / 'testData'.
2527
directory createDirectory.
26-
28+
2729
commaQuoteCsvFile := directory / 'commaQuote.csv'.
28-
tabQuoteCsvFile := directory / 'tabQuote.csv'.
29-
30-
dataFrame := DataFrame withRows: #(
31-
(2.4 true 'rain')
32-
(0.5 true 'rain')
33-
(-1.2 true 'snow')
34-
(-2.3 false '-')
35-
(3.2 true 'rain')).
36-
37-
dataFrame columnNames: #(temperature precipitation type).
38-
dataFrame rowNames: (#('01:10' '01:30' '01:50' '02:10' '02:30')
39-
collect: #asTime).
30+
tabQuoteCsvFile := directory / 'tabQuote.csv'.
31+
32+
dataFrame := DataFrame withRows: #( #( 2.4 true 'rain' ) #( 0.5 true 'rain' ) #( -1.2 true 'snow' ) #( -2.3 false '-' ) #( 3.2 true 'rain' ) ).
33+
34+
dataFrame columnNames: #( temperature precipitation type ).
35+
dataFrame rowNames: (#( '01:10' '01:30' '01:50' '02:10' '02:30' ) collect: #asTime)
4036
]
4137

4238
{ #category : #tests }
@@ -45,7 +41,7 @@ DataFrameCsvWriterTest >> testWriteToCsv [
4541
dataFrame writeToCsv: commaQuoteCsvFile.
4642
actual := self readFile: commaQuoteCsvFile.
4743
expected := TestCsvStrings commaQuoteCsvString.
48-
self assert: actual lines equals: expected lines.
44+
self assert: actual lines equals: expected lines
4945
]
5046

5147
{ #category : #tests }
@@ -56,7 +52,7 @@ DataFrameCsvWriterTest >> testWriteToCsvLineEndLf [
5652
dataFrame writeTo: commaQuoteCsvFile using: writer.
5753
actual := self readFile: commaQuoteCsvFile.
5854
expected := String lf join: TestCsvStrings commaQuoteCsvString lines.
59-
self assert: actual lines equals: expected lines.
55+
self assert: actual lines equals: expected lines
6056
]
6157

6258
{ #category : #tests }
@@ -65,5 +61,5 @@ DataFrameCsvWriterTest >> testWriteToCsvWithSeparatorTab [
6561
dataFrame writeToCsv: tabQuoteCsvFile withSeparator: Character tab.
6662
actual := self readFile: tabQuoteCsvFile.
6763
expected := TestCsvStrings tabQuoteCsvString.
68-
self assertCollection: actual lines equals: expected lines.
64+
self assertCollection: actual lines equals: expected lines
6965
]

src/DataFrame-IO-Tests/DataFrameJsonReaderTest.class.st

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,53 @@ DataFrameJsonReaderTest >> createFileNamed: name withContents: aString [
1616
| stream |
1717
stream := (directory / name) writeStream.
1818
stream nextPutAll: aString.
19-
stream close.
19+
stream close
2020
]
2121

2222
{ #category : #running }
2323
DataFrameJsonReaderTest >> setUp [
2424
super setUp.
2525
directory := FileSystem memory workingDirectory / 'testDataForJson'.
2626
directory createDirectory.
27-
27+
2828
self createFileNamed: 'column.json' withContents: TestJsonStrings columnJsonString.
2929
self createFileNamed: 'index.json' withContents: TestJsonStrings indexJsonString.
3030
self createFileNamed: 'nonNull1.json' withContents: TestJsonStrings nonNullJsonString1.
3131
self createFileNamed: 'records.json' withContents: TestJsonStrings recordsJsonString.
3232
self createFileNamed: 'split.json' withContents: TestJsonStrings splitJsonString.
3333
self createFileNamed: 'values.json' withContents: TestJsonStrings valuesJsonString.
34-
34+
3535
df := DataFrame withRows: #(
3636
(1 2 nil nil)
3737
(nil 2 3 nil)
3838
(nil nil nil 5)
3939
(1 nil 2 nil)).
40-
40+
4141
dfWithColNames := df deepCopy.
4242
dfWithColNames columnNames: #('col1' 'col2' 'col3' 'col4').
43-
43+
4444
dfWithRowNames := df deepCopy.
4545
dfWithRowNames rowNames: #('row1' 'row2' 'row3' 'row4').
46-
46+
4747
dfWithRowColNames := df deepCopy.
4848
dfWithRowColNames columnNames: #('col1' 'col2' 'col3' 'col4').
49-
dfWithRowColNames rowNames: #('row1' 'row2' 'row3' 'row4').
50-
51-
52-
53-
49+
dfWithRowColNames rowNames: #('row1' 'row2' 'row3' 'row4')
5450
]
5551

5652
{ #category : #running }
5753
DataFrameJsonReaderTest >> sortByRowColNames: inputDf [
5854
"Sorts df according to column and row names"
59-
55+
6056
| sortedRowNames sortedColNames dfColSorted outputDf |
6157
sortedRowNames := inputDf rowNames sorted.
6258
sortedColNames := inputDf columnNames sorted.
63-
59+
6460
dfColSorted := DataFrame withRowNames: inputDf rowNames.
6561
sortedColNames do: [ :col | dfColSorted addColumn: (inputDf column: col) asArray named: col ].
66-
62+
6763
outputDf := DataFrame withColumnNames: dfColSorted columnNames.
6864
sortedRowNames do: [ :row | outputDf addRow: (dfColSorted row: row) asArray named: row ].
69-
65+
7066
^ outputDf
7167
]
7268

@@ -75,74 +71,74 @@ DataFrameJsonReaderTest >> testReadFrom [
7571
| output |
7672

7773
output := DataFrameJsonReader new readFrom: directory / 'nonNull1.json'.
78-
79-
self assert: (self sortByRowColNames: output) equals: dfWithColNames.
74+
75+
self assert: (self sortByRowColNames: output) equals: dfWithColNames
8076
]
8177

8278
{ #category : #tests }
8379
DataFrameJsonReaderTest >> testReadFromColumns [
8480
| output |
8581

8682
output := DataFrameJsonReader new readFrom: directory / 'column.json'.
87-
88-
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames.
83+
84+
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames
8985
]
9086

9187
{ #category : #tests }
9288
DataFrameJsonReaderTest >> testReadFromIndex [
9389
| output |
9490

9591
output := DataFrameJsonReader new readFrom: directory / 'index.json'.
96-
97-
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames transposed.
92+
93+
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames transposed
9894
]
9995

10096
{ #category : #tests }
10197
DataFrameJsonReaderTest >> testReadFromJson [
10298
| output |
10399
output := DataFrame readFromJson: (directory / 'nonNull1.json').
104-
self assert: (self sortByRowColNames: output) equals: dfWithColNames.
100+
self assert: (self sortByRowColNames: output) equals: dfWithColNames
105101
]
106102

107103
{ #category : #tests }
108104
DataFrameJsonReaderTest >> testReadFromJsonOrient [
109105
| output |
110106
output := DataFrame readFromJson: (directory / 'split.json') orient: 'split'.
111-
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames.
107+
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames
112108
]
113109

114110
{ #category : #tests }
115111
DataFrameJsonReaderTest >> testReadFromRecords [
116112
| output |
117113

118114
output := DataFrameJsonReader new readFrom: directory / 'records.json'.
119-
120-
self assert: (self sortByRowColNames: output) equals: dfWithColNames.
115+
116+
self assert: (self sortByRowColNames: output) equals: dfWithColNames
121117
]
122118

123119
{ #category : #tests }
124120
DataFrameJsonReaderTest >> testReadFromSplit [
125121
| output |
126122

127123
output := DataFrameJsonReader new readFrom: directory / 'split.json'.
128-
129-
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames.
124+
125+
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames
130126
]
131127

132128
{ #category : #tests }
133129
DataFrameJsonReaderTest >> testReadFromString [
134130
| output |
135131

136132
output := DataFrameJsonReader new readFrom: TestJsonStrings nonNullJsonString2.
137-
138-
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames.
133+
134+
self assert: (self sortByRowColNames: output) equals: dfWithRowColNames
139135
]
140136

141137
{ #category : #tests }
142138
DataFrameJsonReaderTest >> testReadFromValues [
143139
| output |
144140

145141
output := DataFrameJsonReader new readFrom: directory / 'values.json'.
146-
147-
self assert: (self sortByRowColNames: output) equals: df.
142+
143+
self assert: (self sortByRowColNames: output) equals: df
148144
]

0 commit comments

Comments
 (0)