Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repeated mangled names in read_csv with duplicate column names #8645

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cpp/src/io/csv/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ table_with_metadata reader::impl::read(rmm::cuda_stream_view stream)
if (opts_.is_enabled_mangle_dupe_cols()) {
// Rename duplicates of column X as X.1, X.2, ...; First appearance
// stays as X
col_name += "." + std::to_string(col_names_histogram[col_name] - 1);
do {
col_name += "." + std::to_string(col_names_histogram[col_name] - 1);
} while (col_names_histogram[col_name]++);
} else {
// All duplicate columns will be ignored; First appearance is parsed
const auto idx = &col_name - col_names_.data();
Expand Down
11 changes: 11 additions & 0 deletions python/cudf/cudf/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,17 @@ def test_csv_reader_column_names(names):
assert list(df) == list(names)


def test_csv_reader_repeated_column_name():
buffer = """A,A,A.1,A,A.2,A,A.4,A,A
1,2,3.1,4,a.2,a,a.4,a,a
2,4,6.1,8,b.2,b,b.4,b,b"""

# pandas and cudf to have same repeated column names
pdf = pd.read_csv(StringIO(buffer))
gdf = cudf.read_csv(StringIO(buffer))
assert_eq(pdf.columns, gdf.columns)


def test_csv_reader_bools_false_positives(tmpdir):
# values that are equal to ["True", "TRUE", "False", "FALSE"]
# when using ints to detect bool values
Expand Down