Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring order for deeply nested lists of dictionaries. #393

Open
explorigin opened this issue Apr 27, 2023 · 5 comments
Open

Ignoring order for deeply nested lists of dictionaries. #393

explorigin opened this issue Apr 27, 2023 · 5 comments

Comments

@explorigin
Copy link

explorigin commented Apr 27, 2023

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.

@seperman
Copy link
Owner

seperman commented 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 by id.
So what happens to the rest of the items in your nested dictionary that don't fall under "root['_embedded']['messages']" ?

@explorigin
Copy link
Author

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

@seperman
Copy link
Owner

@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
Copy link
Author

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants