You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ignoring order for deeply nested lists of dictionaries. #393
I'd like group_by to work with deep lists such as this.
Describe the solution you'd like
Calling like DeepDiff(old, new, ignore_order=True, group_by={"root['_embedded']['messages']": "id"}) would be able to apply different grouping to different areas in the dataset.
Describe alternatives you've considered
I'll just have to manipulate my data myself prior to comparison. The disadvantage of this is that I don't get a diff that reflects the level of nesting of the list.
Hi @explorigin
This is going to be tricky. It seems like you want to diff at the "root['_embedded']['messages']" level. Then group by id.
So what happens to the rest of the items in your nested dictionary that don't fall under "root['_embedded']['messages']" ?
An update on this one, and thanks to everyone for the patience.
Rather than extending group_by to accept a {path: key} mapping, we're adding a dedicated parameter for key-based matching of nested lists, tracked in #664. group_by will stay as it is (root level), so it remains simple.
With the new parameter (working name), the original example would look like:
Records in that list are paired by id, so inserts, removals and reorders no longer cascade into false changes. Globs work too, e.g. root['orders'][*]['items'].
One difference from what was asked here: the list is not converted into an object keyed by id. Results keep real list paths such as root['_embedded']['messages'][1]['status']. That's what lets Delta keep working and lets the new parameter combine with existing options like exclude_paths.
Closing in favour of #664, which adds key-based matching for nested lists as a dedicated parameter while keeping group_by as it is. Follow #664 for progress.
Activity
seperman commentedon May 1, 2023
Hi @explorigin
This is going to be tricky. It seems like you want to diff at the
"root['_embedded']['messages']"level. Then group byid.So what happens to the rest of the items in your nested dictionary that don't fall under
"root['_embedded']['messages']"?explorigin commentedon May 1, 2023
I'd like to convert the list at
"root['_embedded']['messages']"to an object keyed byidand then diff the whole data tree.seperman commentedon May 10, 2023
@explorigin Ah, I see. Ok, that makes more sense than what I mentioned above. I'm curious if this is a very common use case or not.
explorigin commentedon May 30, 2023
It's common for me. :-) The example is a common REST API reply where you have a result and some metadata in one package.
seperman commentedon Nov 19, 2023
We now allow
group_byto take 2 elements. In your case, it needs to take 3.I think we should make
group_bytake arbitrary number of elements.seperman commentedon Nov 16, 2026
An update on this one, and thanks to everyone for the patience.
Rather than extending
group_byto accept a{path: key}mapping, we're adding a dedicated parameter for key-based matching of nested lists, tracked in #664.group_bywill stay as it is (root level), so it remains simple.With the new parameter (working name), the original example would look like:
Records in that list are paired by
id, so inserts, removals and reorders no longer cascade into false changes. Globs work too, e.g.root['orders'][*]['items'].One difference from what was asked here: the list is not converted into an object keyed by
id. Results keep real list paths such asroot['_embedded']['messages'][1]['status']. That's what letsDeltakeep working and lets the new parameter combine with existing options likeexclude_paths.Comments on the design are welcome in #664.
seperman commentedon Nov 16, 2026
Closing in favour of #664, which adds key-based matching for nested lists as a dedicated parameter while keeping
group_byas it is. Follow #664 for progress.