Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Error when column name contains . (dot) #7

Copy link
Copy link
@antopolskiy

Description

@antopolskiy
Issue body actions
$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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.