Reputation: 81
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.
Upvotes: 4
Views: 4860
Reputation: 65
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()
Upvotes: 2