-
-
Notifications
You must be signed in to change notification settings - Fork 240
How to align objects in lists properly? #185
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
Comments
you may have to nest your objects(?) what about this
or
|
Hi @MKaras93 and @testautomation . |
Thanks, I'm currently busy with other projects but I will get back to it when I have some time and let you know if it worked ;) |
@seperman I have a question which is related or similar to original post. Let's assume I have some data like in example below where rows is a list of lists each with one object (that can have more and deeper nested elements than in below example). Each object is identifiable by it's uid.value. How can we make sure that Deepdiff compares the correct objects with each other when we compare two of such data sets? What I have noticed is that Deepdiff may report "false" diffs even when using ignore_order option because it may end up comparing the wrong objects with each other.
|
Hi @testautomation Assuming the 2 iterables contain exactly the same uids, The best thing to do is , sort the 2 iterables by the uid field before passing it to deepdiff. Then set ignore_order=False. That way automatically the correct objects with the same uid are compared with each other. |
fyi: I'm back w/ a new Github handle @wlad. @testautomation is now an org. |
Cool! I will have a new beta release today. I will ping you. It should be way faster than before.
Sep Dehpour
… On May 13, 2020, at 4:50 AM, [TEST] AUTOMATION ENGINEER ***@***.***> wrote:
fyi: I'm back w/ a new Github handle @wlad. @testautomation is now an org.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@wlad Please pull the new changes on the dev branch and test with your data. It should be exponentially faster when ignore_order=True (I hope). I have also added logging so you get some insights while DeepDiff is running. Pass |
Update: The delta module has 100% test coverage now. The tricky part is now that DeepDiff itself should run with or without Numpy. But I want to make sure in one run of pytest, the coverage report reaches 100%. That means some tests should make DeepDiff think Numpy doesn't exist. And the rest should use the Numpy module. Any ideas how to do that? I have not tried it but if I can mutate the |
@seperman We have to solve #193 for me to continue testing
I have no idea how to achieve that in one run but just found that pytest has an option |
I am currently evaluating this library for diffing python dictionaries and we need a way to compare items in a sequence. In our case their our unique IDs such as:
I would prefer not to preprocess making The above is a contrived example to keep things simple, but our use case is a more complex. Ignoring order and using hashing would likely provide a match but at a performance cost, when the true compare function is well known (simply comparing functions). @seperman I would like to get your thoughts on a proposed change that we could help develop if you think it makes sense: Add an option to We would update ( Line 554 in 5b66b96
_diff_iterable_compare_func function that would be very similar to _diff_iterable_in_order except it would have a nested loop and call the compare function across every item to be compared to until it found a match or exhausted the list (in which case it would be marked as removed). Finally we would need to check the new array to see if anything was added in a similar fashion.
First, do you think this approach would work? Secondly, are you open to merging something like this in if we develop a patch? |
Hi @dtorres-sf Perhaps we could target this expensive calculation itself by allowing the user to pass a function like what you described in Line 747 in 5b66b96
For example if we have
and
which has only model name changed in ids 2 and 3, then deepdiff via hashing finds out that indexes 1 and 2 have changed between the 2 iterables but indexes 0 are not. It passes this info to |
@seperman I just hacked up a version to do what you mentioned for some quick testing. The good news is I was able to get matching to work correctly, but the bad news is that the Delta object can not be used to recreate the original object (because ignore_order is true). Here is the test I was using (note: I did not pass in a
I am not sure the best way to solve this, it would almost need a new report item such as "iterable_item_moved". |
Hello @MKaras93 @wlad and @dtorres-sf |
Hi. Sorry, I don't know whether it's a bug/feature or just a question. I've asked it some time ago on StackOverflow, but didn't receive any answer, so I decided to try here.
I'm trying to compare two lists of objects (dicts in this case) with deepdiff:
The problem is that I need a different way of aligning objects. In my project a particular state (for example
war
) have a strict life cycle: appears aspending
, transforms toactive
and disappears. I want to use deepdiff to track these changes. Objects with different names are different objects and I don't want them to align with each other.So the result I expect is:
Is there a way I can modify my object to align it properly? I've tried replacing the dict with a class with custom
__eq__
method, but it didn't work. Do you have any other suggestion how I can make objects with the samename
align only with each other?Here is the original stack overflow question.
The text was updated successfully, but these errors were encountered: