deepdiff icon indicating copy to clipboard operation
deepdiff copied to clipboard

Ignoring order for deeply nested lists of dictionaries.

Open explorigin opened this issue 2 years ago • 5 comments
trafficstars

Is your feature request related to a problem? Please describe. I have a dataset that looks like:

{
	"_links": {
		"self": {
			"href": "/accounts/036aa770-b6fe-11ed-b489-b625a1e46b37/messages"
		}
	},
	"_embedded": {
		"messages": [
			{
				"id": "c589614c-b6cb-11ed-9083-7cb91a971123",
				"channel": "email",
				"contact": {},
				"status": "delivered",
			},
			{
				"id": "c5892790-b6cb-11ed-8a7c-a8944afb6fba",
				"channel": "email",
				"contact": {},
				"status": "delivered"
			}
		]
	}
}

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.

explorigin avatar Apr 27 '23 16:04 explorigin

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']" ?

seperman avatar May 01 '23 05:05 seperman

I'd like to convert the list at "root['_embedded']['messages']" to an object keyed by id and then diff the whole data tree.

explorigin avatar May 01 '23 12:05 explorigin

@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.

seperman avatar May 10 '23 07:05 seperman

It's common for me. :-) The example is a common REST API reply where you have a result and some metadata in one package.

explorigin avatar May 30 '23 19:05 explorigin

We now allow group_by to take 2 elements. In your case, it needs to take 3. I think we should make group_by take arbitrary number of elements.

seperman avatar Nov 19 '23 15:11 seperman