Skip to content

Commit

Permalink
Add test for #1197 (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccleva authored Jan 3, 2025
1 parent a923338 commit 3c443ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/tech/tablesaw/io/FileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ private void renameDuplicateColumnHeaders(String[] headerNames) {
Map<String, Integer> nameCounter = new HashMap<>();
for (int i = 0; i < headerNames.length; i++) {
String name = headerNames[i];
Integer count = nameCounter.get(name.toLowerCase());
String lowerCase = name.toLowerCase();
Integer count = nameCounter.get(lowerCase);
if (count == null) {
nameCounter.put(name.toLowerCase(), 1);
nameCounter.put(lowerCase, 1);
} else {
count++;
nameCounter.put(name.toLowerCase(), count);
nameCounter.put(lowerCase, count);
headerNames[i] = name + "-" + count;
}
}
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/tech/tablesaw/io/csv/CsvReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ void allowDuplicateColumnNames() throws IOException {
assertEquals("Col1-2", dupes.columnNames().get(1));
}

@Test
void allowDuplicateColumnNamesInsensitive() {
Reader reader2 =
new StringReader(
"Col1" + COMMA + "col1" + LINE_END + "first" + COMMA + "second" + LINE_END);
Table dupes =
Table.read().csv(CsvReadOptions.builder(reader2).allowDuplicateColumnNames(true).build());
assertEquals("Col1", dupes.columnNames().get(0));
assertEquals("col1-2", dupes.columnNames().get(1));
}

@Test
public void testWithColumnSKIPWithoutHeader() throws IOException {
// Read the CSV file
Expand Down

0 comments on commit 3c443ed

Please sign in to comment.