Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude "type_changes" completely from deep diff as i only care about value changed?

from deepdiff import DeepDiff


t1 = {1:1, 2:2, 3:3}
t2 = {1:1, 2:"2", 3:3}
print(DeepDiff(t1, t2), indent=2)

Output:

{ 'type_changes': { 'root[2]': { 'new_type': <class 'str'>,
                                 'new_value': '2',
                                 'old_type': <class 'int'>,
                                  'old_value': 2
}}}

I want is only value changes in my output and exclude 'type_changes'. I have to compare nested dictionaries and i don't care about type.

like image 1000
darshpreet narula Avatar asked Oct 18 '25 13:10

darshpreet narula


1 Answers

From DeepDiff's Documentation: DeepDiff Docs

ignore_type_in_groups -

Ignore type changes between members of groups of types. For example if you want to ignore type changes between float and decimals etc. Note that this is a more granular feature.

So in your case, when the old_type is integer and the new_type is a string -

print(DeepDiff(t1, t2), indent=2, ignore_type_in_groups=[(int, str)])

The output would be -

{}

Another available option is to convert your DeepDiff object into Dictionary/JSON and control it however you desire.

dict = DeepDiff(t1, t2).to_dict()
like image 156
Redbulbul Avatar answered Oct 21 '25 01:10

Redbulbul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!