Skip to content

Support for empty CSV files #18

Open
@gfiorav

Description

@gfiorav

Thanks for this lib!

I've noticed that the compare method doesn't work if one of the csv files is empty.

Steps to reproduce

a.csv

id,foo,bar

b.csv

id,foo,bar
1,hey,ho
2,lets,go
from csv_diff import compare
from csv_diff import load_csv

diff: dict = compare(
    load_csv(open("a.csv"), key="id"),
    load_csv(open("b.csv"), key="id"),
)

for added_row in added:
     print(added_row)

Expected result

{"id": 1, "foo": "hey", "bar": "ho"}
{"id": 2, "foo": "lets", "bar": "go"}

Actual result

Traceback (most recent call last):
  File "REDACTED.py", line 165, in <module>
    diff: dict = compare(
  File "REDACTED/python3.9/site-packages/
csv_diff/__init__.py", line 58, in compare
    previous_columns = set(next(iter(previous.values())).keys())
StopIteration

I'm using Python 3.9.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions