You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: Duplicate key causes undefined behaviour, user not warned #31
The reproducer combines two things that need separate checks before constructing the keyed dictionary:
a.csv data record 2 has three fields for a four-column header. The current dict(zip(headings, line)) leaves d absent.
Both inputs repeat key 1; constructing {keyfn(r): r for r in rows} keeps the last row for that key. A missing field can therefore affect the later inferred column set.
For an explicit preflight/review workaround, I tested these exact inputs with Local Row Check v1.1.0, a free MIT tool I publish. From that checkout:
python3 rowcheck.py a.csv b.csv --key a --compare-columns b c d --out original-report
Actual result, exit 2, with no report directory created:
Error: a.csv: data record 2 has 3 fields; expected 4
To test duplicates separately, I made a clearly separate, valid-width variant a-valid.csv where the missing d is an explicit empty field:
a,b,c,d1,2,3,41,2,3,3,2,3,4
With b.csv unchanged:
python3 rowcheck.py a-valid.csv b.csv --key a --compare-columns b c d --out valid-duplicate-report
The executed result has all four key-1 source rows in review.csv (two per input), while key 3 is the one unambiguous shared pair. No key-1 row is selected or discarded, and those ambiguous rows are excluded from value comparisons. The command reports zero changed cells only for the one unambiguous pair.
This is an external validation/review workaround, not a patch to csv-diff. The original malformed input is rejected; adding the trailing comma above is an explicit demonstration variant, not an automatic data repair. A native reader fix could likewise validate width and key uniqueness before converting rows to a dictionary.
Activity
jhrch7 commentedon Nov 2, 2026
The reproducer combines two things that need separate checks before constructing the keyed dictionary:
a.csvdata record 2 has three fields for a four-column header. The currentdict(zip(headings, line))leavesdabsent.1; constructing{keyfn(r): r for r in rows}keeps the last row for that key. A missing field can therefore affect the later inferred column set.For an explicit preflight/review workaround, I tested these exact inputs with Local Row Check v1.1.0, a free MIT tool I publish. From that checkout:
Actual result, exit 2, with no report directory created:
To test duplicates separately, I made a clearly separate, valid-width variant
a-valid.csvwhere the missingdis an explicit empty field:With
b.csvunchanged:The executed result has all four key-
1source rows inreview.csv(two per input), while key3is the one unambiguous shared pair. No key-1row is selected or discarded, and those ambiguous rows are excluded from value comparisons. The command reports zero changed cells only for the one unambiguous pair.This is an external validation/review workaround, not a patch to
csv-diff. The original malformed input is rejected; adding the trailing comma above is an explicit demonstration variant, not an automatic data repair. A native reader fix could likewise validate width and key uniqueness before converting rows to a dictionary.