seperman / deepdiff

DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
http://zepworks.com
Other
2.01k stars 221 forks source link

How to get result if max_diffs used #276

Open drsasa opened 2 years ago

drsasa commented 2 years ago

Hi,

Is there a way to achive, to know that there is difference but to exit on max_diffs=1 ?

For example:

a1 = {"a": 1, "b": [3,2,1]}
a2 = {"b": [1,2,3], "a": 1}

result = DeepDiff(
    a1,
    a2,
    ignore_order=True,
    report_repetition=True,
    ignore_string_case=True,
    exclude_regex_paths=[r"(?i)\['link'\]$"],
    ignore_string_type_changes=True,
    max_diffs=1
)

and

a1 = {"a": 1, "b": [3,2,1]}
a2 = {"b": [1,2,3], "a": 9999}

result = DeepDiff(
    a1,
    a2,
    ignore_order=True,
    report_repetition=True,
    ignore_string_case=True,
    exclude_regex_paths=[r"(?i)\['link'\]$"],
    ignore_string_type_changes=True,
    max_diffs=1
)

will return same result {} with {'PASSES COUNT': 0, 'DIFF COUNT': 2, 'DISTANCE CACHE HIT COUNT': 0, 'MAX PASS LIMIT REACHED': False, 'MAX DIFF LIMIT REACHED': True}

But they are not same, if we do not use max_diffs only second example is different.

Is there a way to achive this ?

Thanks in advance.

seperman commented 2 years ago

Hi @drsasa Sorry for the very late response. max_diffs in DeepDiff is basically telling it to quit diffing once certain number of comparisons are made. Not necessarily certain number of differences are detected. This question usually comes up because the diff calculation can be heavy. Your best bet to tune DeepDiff to get you some answer quickly is explained here: https://zepworks.com/deepdiff/current/optimizations.html I would start with https://zepworks.com/deepdiff/current/ignore_order.html#cutoff-intersection-for-pairs-label and https://zepworks.com/deepdiff/current/ignore_order.html#cutoff-distance-for-pairs for getting a less granular result when ignore_order=True