Skip to content

Support for empty CSV files #18

Open

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.

Activity

  1. sid1333 commented on Apr 25, 2022

    @sid1333

    File "REDACTED/python3.9/site-packages/
    csv_diff/__init__.py", line 58, in compare

    previous_columns = set(next(iter(previous.values())).keys()) if previous else set()
    current_columns = set(next(iter(current.values())).keys()) if current else set()
    
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