Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when column name contains . (dot) #7

Closed
antopolskiy opened this issue Aug 21, 2020 · 1 comment
Closed

Error when column name contains . (dot) #7

antopolskiy opened this issue Aug 21, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@antopolskiy
Copy link

antopolskiy commented Aug 21, 2020

$csv-diff --version
csv-diff, version 0.6

Consider the following example, which works correctly:

import csv_diff
from io import StringIO
csv_diff.compare(csv_diff.load_csv(StringIO("id,a,b,c c,d\n0,2,3,4,5"), key="id"),
                 csv_diff.load_csv(StringIO("id,a,b,c c,d\n0,2,4,5,5"), key="id"))

Output:

{'added': [],
 'removed': [],
 'changed': [{'key': '0', 'changes': {'b': ['3', '4'], 'c c': ['4', '5']}}],
 'columns_added': [],
 'columns_removed': []}

If I add a . inside the column name of "c c" -> "c. c" it breaks

import csv_diff
from io import StringIO
csv_diff.compare(csv_diff.load_csv(StringIO("id,a,b,c. c,d\n0,2,3,4,5"), key="id"),
                 csv_diff.load_csv(StringIO("id,a,b,c. c,d\n0,2,4,5,5"), key="id"))

Output:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-5902626c5fa9> in <module>
      2 from io import StringIO
      3 csv_diff.compare(csv_diff.load_csv(StringIO("id,a,b,c. c,d\n0,2,3,4,5"), key="id"),
----> 4                  csv_diff.load_csv(StringIO("id,a,b,c. c,d\n0,2,4,5,5"), key="id"))

~/anaconda3/envs/py37/lib/python3.7/site-packages/csv_diff/__init__.py in compare(previous, current)
     65                         "changes": {
     66                             field: [prev_value, current_value]
---> 67                             for _, field, (prev_value, current_value) in d
     68                         },
     69                     }

~/anaconda3/envs/py37/lib/python3.7/site-packages/csv_diff/__init__.py in <dictcomp>(.0)
     65                         "changes": {
     66                             field: [prev_value, current_value]
---> 67                             for _, field, (prev_value, current_value) in d
     68                         },
     69                     }

TypeError: unhashable type: 'list'

From what I can understand, for some reason when the column name contains ., the field become a list instead of a str (e.g. ["c. c."] instead of "c. c"), and it breaks the construction of the dictionary.

@simonw simonw added the bug Something isn't working label Aug 22, 2020
@simonw
Copy link
Owner

simonw commented Oct 16, 2020

This seems to be weird behavior from dictdiffer. I can work around it.

@simonw simonw closed this as completed in 9574395 Oct 16, 2020
simonw added a commit that referenced this issue Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants