simonw / csv-diff

Python CLI tool and library for diffing CSV and JSON files
Apache License 2.0
292 stars 47 forks source link

error when no key precised #3

Closed MainHanzo closed 3 years ago

MainHanzo commented 4 years ago

the tool works well when we have a id precised by user as the key. However I think when the user doesn't use the '--key' option, it's not working as expected.

for example: ----1.csv---- """id,name,age 1,Cleo,5 2,Pancakes,2"""

----2.csv---- """id,name,age 1,Cleo,5 2,Pancakes,3"""

and we launch with no key option : csv-diff 1.csv 2.csv we will get: "2 rows added, 2 rows removed

2 rows added

id: 1 name: Cleo age: 5

id: 2 name: Pancakes age: 2

2 rows removed

id: 1 name: Cleo age: 5

id: 2 name: Pancakes age: 4

"

while i expect this: " 1 row added, 1 row removed 1 row added: id:2 name: Pancakes age: 2 1 row removed: id: 2 name: Pancakes age: 4

"

the problem is caused because that the hash of the line is stored as a hash object, and even two lines are the same content, the memo locations are different. So they are different objects.

I have corrected this feature, if you like, I can upload it through a pull request.

simonw commented 4 years ago

Thanks - please do open a pull request for this!

MainHanzo commented 4 years ago

Thanks - please do open a pull request for this!

PR Done! :)