Comments (10)
I made some adjustments and it works with list containing lists but not lists containing dictionaries.
We will have to fork Pickle and make it consistent in order to get the best results.
from deepdiff.
It is in 2.1.1
from deepdiff.
Thanks for quick fix.
But it doesn't work if i have nested list in nested list:
>>> a = [1, 2, [3, [4, 5]]]
>>> b = [[[5, 4], 3], 2, 1]
>>> DeepDiff(a, b, ignore_order=True)
2016-08-10 12:24:08,807 WARNING Unable to order data type: <class 'list'>. Ignore order might be giving inaccurate results.
Traceback (most recent call last):
File "/home/anatoly/Work/unfork-ng/.env/lib/python3.5/site-packages/deepdiff/diff.py", line 81, in order_unordered
sorted_by_type = sorted(data, key=lambda x: type(x))
TypeError: unorderable types: list() < int()
2016-08-10 12:24:08,807 WARNING Unable to order data type: <class 'list'>. Ignore order might be giving inaccurate results.
Traceback (most recent call last):
File "/home/anatoly/Work/unfork-ng/.env/lib/python3.5/site-packages/deepdiff/diff.py", line 81, in order_unordered
sorted_by_type = sorted(data, key=lambda x: type(x))
TypeError: unorderable types: int() < list()
{'iterable_item_added': {'root[0]': [[5, 4], 3]}, 'iterable_item_removed': {'root[2]': [3, [4, 5]]}}
Have some another not working example with nested list in dictionary values:
>>> a = [{1: [2, 3], 4: [5, [6, 7]]}]
>>> b = [{4: [[7, 6], 5], 1: [3, 2]}]
>>> DeepDiff(a, b, ignore_order=True)
2016-08-10 12:21:44,909 WARNING Unable to order data type: <class 'list'>. Ignore order might be giving inaccurate results.
Traceback (most recent call last):
File "/home/anatoly/Work/unfork-ng/.env/lib/python3.5/site-packages/deepdiff/diff.py", line 81, in order_unordered
sorted_by_type = sorted(data, key=lambda x: type(x))
TypeError: unorderable types: list() < int()
2016-08-10 12:21:44,910 WARNING Unable to order data type: <class 'list'>. Ignore order might be giving inaccurate results.
Traceback (most recent call last):
File "/home/anatoly/Work/unfork-ng/.env/lib/python3.5/site-packages/deepdiff/diff.py", line 81, in order_unordered
sorted_by_type = sorted(data, key=lambda x: type(x))
TypeError: unorderable types: int() < list()
{'iterable_item_added': {'root[0]': {1: [3, 2], 4: [[7, 6], 5]}}, 'iterable_item_removed': {'root[0]': {1: [2, 3], 4: [5, [6, 7]]}}}
from deepdiff.
I'm gonna have to write another serializer instead of Pickle to make this work right. Will keep you posted.
from deepdiff.
Ok, thanks.
from deepdiff.
I had some time to finally write a custom content hash for this issue. It passes the sample inputs you have mentioned here. https://github.com/seperman/deepdiff/tree/contenthash
Please check it out and let me know if it works fine.
from deepdiff.
Found another weird case with repetitions:
If repetition is in top level list it's ok:
>>> a = [1, 2, [3, 4]]
>>> b = [[4, 3], 2, 1, 1]
>>> DeepDiff(a, b, ignore_order=True)
{}
>>> a = [1, 2, [3, 4]]
>>> b = [[4, 3], 2, 1, 1]
>>> DeepDiff(a, b, ignore_order=True, report_repetition=True)
{'repetition_change': {'root[0]': {'value': 1, 'new_indexes': [2, 3], 'new_repeat': 2, 'old_indexes': [0], 'old_repeat': 1}}}
But if repetition in nested list, it works another way:
>>> a = [1, 2, [3, 4]]
>>> b = [[4, 3, 3], 2, 1]
>>> DeepDiff(a, b, ignore_order=True)
{'iterable_item_removed': {'root[2]': [3, 4]}, 'iterable_item_added': {'root[0]': [4, 3, 3]}}
For me it's fine, but I think it's weird that logic is different for top-level and nested lists
from deepdiff.
@anatoly-kussul I merged the PR. It seems it does a great job when ignoring order now. But it does not do it right as far as reporting repetition. The reason is that once it identifies to items as being the same when order is ignored, it won't bother to check what is inside them for repetitions. I have some ideas how to do this properly later.
from deepdiff.
from deepdiff.
Thanks a lot. 👍
from deepdiff.
Related Issues (20)
- Documentation on how to consume keys HOT 2
- Error after comparing: Can not produce a hash (type datetime.date doesn't define __round__ method) HOT 1
- parse_path() cannot parse a path HOT 4
- Is there a way to systematically cycle through all corresponding attributes that haven't changed? HOT 1
- support compre string as float specify precision HOT 1
- Error when comparing two nested dicts with 2 added fields HOT 5
- why exclude_regex_paths dont work with ignore_order HOT 1
- Change of integer attribute is not detected HOT 3
- DeepDiff include_path param doesn't work with list of dictionaries HOT 1
- Instantiating a Delta with a flat_dict_list unexpectedly mutates the flat_dict_list HOT 1
- DeepDiff result got errors but not raising an exception
- Documentation on how to create an object only containing changed elements. HOT 1
- DeepDiff cannot compare two zero-dimensional `ndarrays` HOT 2
- Deepdiff incompatible with numpy 2.0 HOT 3
- DeepDiff cannot distinguish between datetime timezones HOT 1
- DeepDiff significiant digit 0 is comparing digits after the decimal point
- deepdiff diff error when i haved set a custom iterable_compare_func HOT 1
- load 2 json files to dict, the compare result is not correct HOT 1
- exclude_regex_paths does not work correctly with regular expressions including $
- TypeError when diffing dict that have bytes keys HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepdiff.