Skip to content

Bug: StopIteration crash when diffing empty CSV files #52

Open

Description

@its-Sohan

when running csv-diff on two csv files that contain only headers
and no data rows, the tool crashes with stopiteration instead of
returning "no differences" or an empty diff.

steps to reproduce:

echo "id,name,age" > a.csv
echo "id,name,age" > b.csv
csv-diff a.csv b.csv --key=id
expected behavior:
should exit cleanly with no output or "0 rows changed" message.
actual behavior:
crashes with stopiteration:
traceback (most recent call last):
  file "/home/sohan/projects/csv-diff/venv/bin/csv-diff", line 8, in <module>
    sys.exit(cli())
  ...
  file "/home/sohan/projects/csv-diff/csv_diff/__init__.py", line 64, in compare
    previous_columns = set(next(iter(previous.values())).keys())
                           ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
stopiteration
root cause:
in csv_diff/__init__.py lines 64-65:
previous_columns = set(next(iter(previous.values())).keys())
current_columns = set(next(iter(current.values())).keys())
when both files have no data rows, load_csv returns {},
and next(iter({}.values())) raises stopiteration.

Activity

  1. jhrch7 commented on Nov 3, 2026

    @jhrch7

    For a CSV-only workaround for the header-only case, the free Local Row Check 1.1.0 source ZIP handles this fixture. After unzipping, run in that folder:

    printf 'id,name,age\n' > a.csv
    printf 'id,name,age\n' > b.csv
    python3 rowcheck.py a.csv b.csv --key id --compare-columns name age --out report

    I ran that exact fixture on the pinned v1.1.0 source (d6cd764): exit status 0, with 0 input rows on either side and 0 changed cells. The generated CSV reports contain their headers and no data rows; report/manifest.json records the counts and hashes.

    A second run with the same header-only left input and two data rows on the right also exited 0: both rows appeared in only_right.csv, with no shared/review rows or changed cells.

    This produces a report directory with exact-string cell comparisons; ambiguous blank/duplicate keys go to review. It does not provide csv-diff's JSON/Python API or change the upstream bug.

    Disclosure: the linked tool is an affiliated project. This note and test setup were AI-generated; both runs were actually executed on macOS/Python 3.14.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions