Skip to content

Commit

Permalink
Fix empty csv test (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccleva authored Jan 3, 2025
1 parent fd4f541 commit c29a57e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/main/java/tech/tablesaw/io/FileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public String[] getColumnNames(
if (options.header()) {

String[] headerNames = parser.parseNext();

if (headerNames == null) {
// no header because file is empty
return new String[] {};
}

// work around issue where Univocity returns null if a column has no header.
for (int i = 0; i < headerNames.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/tech/tablesaw/io/csv/CsvReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public void testReadFailure2() throws IOException {

@Test
public void testEmptyFileHeaderEnabled() throws IOException {
Table table1 = Table.read().csv(CsvReadOptions.builder("../data/empty_file.csv").header(false));
Table table1 = Table.read().csv(CsvReadOptions.builder("../data/empty_file.csv").header(true));
assertEquals("empty_file.csv: 0 rows X 0 cols", table1.shape());
}

Expand Down

0 comments on commit c29a57e

Please sign in to comment.