Repository navigation
Reject duplicate CSV/TSV column names instead of dropping values - #987
Jun-shisheng wants to merge 1 commit into
Conversation
|
Should the SQLite import path also catch headers that differ only in ASCII case? At |
atishay-kasliwal
left a comment
There was a problem hiding this comment.
name,name / dog,cat now exits 1 with Duplicate column names: name from insert --csv and from memory; main created one name column holding cat. The 5 new tests fail on main, and all 151 tests in the three touched files pass here. A single blank trailing header (a,b,) loads the same as before.
| duplicates = _duplicate_headers(headers) | ||
| if duplicates: | ||
| raise click.ClickException( | ||
| "Duplicate column names: {}".format(", ".join(duplicates)) |
There was a problem hiding this comment.
Exports with two or more empty trailing headers, like a,b,, (common from spreadsheets), now hit this with Error: Duplicate column names: and nothing after the colon, the same from memory. Main loaded them, keeping only the last blank column's value, so rejecting them makes sense, but the message is hard to act on. Quoting the names (repr, or '"{}"') would show "".
Fixes #986.
CSV/TSV files with duplicate column names were accepted and lost data silently.
insert --csv/--tsvbuilt rows withdict(zip(headers, row)), so the last value for a repeated header won. A file like:created a single
namecolumn containingcat, and exited 0.sqlite-utils memoryhad the same problem becausecsv.DictReaderalso keeps only the last duplicate.Both paths now reject duplicate headers:
insert/upsertexit 1 withError: Duplicate column names: namebefore creating the table.rows_from_file()raisesRowErrorwhen iterated, andmemoryturns that into the same CLI error.Tests
Added regression tests for
insert --csv,insert --tsv,rows_from_file()CSV/TSV, andmemory. Full suite passes:python -m pytest -q # 1635 passed, 17 skipped📚 Documentation preview 📚: https://sqlite-utils--987.org.readthedocs.build/en/987/