Repository navigation
Conversation
Author
|
I’ve opened #56 with a fix for this. |
HRtech-lab
reviewed
Nov 26, 2026
HRtech-lab
left a comment
There was a problem hiding this comment.
The missing-field diagnostic works with --format=tsv, but default delimiter detection can silently turn the same input into a misleading diff. This pair reproduces it on b466aec:
printf 'id\tname\tage\n1\tCleo\t4\n2\tPancakes\n' > old.tsv
printf 'id\tname\tage\n1\tCleo\t4\n2\tPancakes\t2\n' > new.tsv
csv-diff old.tsv new.tsvThe command exits 0 and reports 3 columns added, 1 column removed, 2 rows added, 2 rows removed. With --key=id, it raises KeyError('id'). With --format=tsv --key=id, it correctly reports Line 3: expected 3 fields but found 2.
The short row prevents Sniffer from detecting the tabs in old.tsv, so the comma fallback treats its entire header as one field. A regression test using the default CLI options would catch this alongside the explicit-format case.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30
Problem: If a CSV row has fewer fields than the header, csv-diff crashes later in
compare() with "ValueError: not enough values to unpack", which does not explain the cause.
Root cause: load_csv() builds rows with dict(zip(headings, line)). zip() stops at the
shorter list, so missing fields are silently dropped and the row ends up with fewer columns
than the header. dictdiffer then reports an "add" instead of a "change", which compare()
cannot unpack.
Fix:
Error: a.csv: Line 4: expected 4 fields but found 3Happy to add a warning for that case if you'd like.
Tests: Added tests for missing fields, empty fields, quoted commas, blank lines,
extra fields and the CLI error message. Full suite passes locally (30 passed).
AI assistance: I used Claude to help understand the root cause and draft parts of the
tests and this description; I ran and verified everything locally.