File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,28 @@ DataFrameCsvReaderTest >> testReadCsv [
7878 self assert: actualDataFrame equals: dataFrameWithoutRowNames
7979]
8080
81+ { #category : #tests }
82+ DataFrameCsvReaderTest >> testReadCsvWithColumnNamesWithSeparator [
83+
84+ | controlDataFrame customColumnNames |
85+
86+ customColumnNames := #('Col1' 'Col2' 'Col3' 'Col4') .
87+
88+ controlDataFrame := DataFrame
89+ readFromCsv: tabCsvFile
90+ withColumnNames: customColumnNames
91+ separator: Character tab.
92+
93+ self
94+ assertCollection: controlDataFrame columnNames
95+ equals: customColumnNames asOrderedCollection.
96+
97+ " The original header is counted as a normal row now"
98+ self
99+ assert: controlDataFrame size
100+ equals: 6 .
101+ ]
102+
81103{ #category : #tests }
82104DataFrameCsvReaderTest >> testReadCsvWithRowNames [
83105 | actualDataFrame |
Original file line number Diff line number Diff line change @@ -37,6 +37,19 @@ DataFrame class >> readFromCsv: aFileReference [
3737 ^ self readFrom: aFileReference using: reader
3838]
3939
40+ { #category : #' *DataFrame-IO' }
41+ DataFrame class >> readFromCsv: aFileReference withColumnNames: anArrayOfColumnNames separator: aSeparator [
42+
43+ | dataFrame |
44+
45+ dataFrame := DataFrameCsvReader new
46+ separator: aSeparator;
47+ columnNames: anArrayOfColumnNames;
48+ readFrom: aFileReference.
49+ dataFrame calculateDataTypes.
50+ ^ dataFrame.
51+ ]
52+
4053{ #category : #' *DataFrame-IO' }
4154DataFrame class >> readFromCsv: aFileReference withSeparator: aSeparator [
4255 | reader |
Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ Class {
4242 #category : #' DataFrame-IO-Core'
4343}
4444
45+ { #category : #reading }
46+ DataFrameCsvReader >> columnNames: aCollectionOfString [
47+ " Set the receiver' s column names"
48+
49+ columnNames := aCollectionOfString
50+ ]
51+
4552{ #category : #reading }
4653DataFrameCsvReader >> createDataFrame [
4754 | df |
@@ -91,7 +98,9 @@ DataFrameCsvReader >> initialize [
9198
9299{ #category : #reading }
93100DataFrameCsvReader >> readColumnNamesWith: aReader [
94- columnNames := aReader readHeader.
101+ " Set the receiver's column names if they were not manually set"
102+
103+ columnNames ifNil: [ columnNames := aReader readHeader ].
95104
96105 self includeRowNames ifTrue: [
97106 columnNames := columnNames copyWithoutFirst ]
You can’t perform that action at this time.
0 commit comments