Question: Does deepDiff only compare the values that both dictionaries have in common?
nh916 opened this issue · 4 comments
Description
I've noticed, that when I am comparing 2 dictionaries that it only compares the fields that both dictionaries have in common and finds if the values are different.
I looked on the documentation and it said that it should be comparing all the fields and whatever that is missing from one it should flag as a difference and report it. However, it seems to only flag the fields that both have in common but have different values for me. Not sure what is going on
My code
exclude_regex_paths = [
r"root(\[.*\])?\['uid'\]"
]
# Compare the JSONs
diff = DeepDiff(my_dict_1,my_dict_2,exclude_regex_paths=exclude_regex_paths)
I thought I was telling it to ignore the UID
field if found nested anywhere or nested multiple times within the dictionary
@nh916 without having reproducible code, the only reason why the items are skipped is because of the exclude regex. If you have reproducible code please paste it here.
Hi @nh916
Your regex is fine. Here is a sample code that does what it is supposed to do:
In [26]: from deepdiff import DeepDiff
...:
...: t1 = [{
...: "key": "val1",
...: "key4": "val4",
...: "uid": 10,
...: }]
...:
...: t2 = [{
...: "key": "val2",
...: "key2": "val3",
...: "uid": 11,
...: }]
...:
...: DeepDiff(t1, t2, exclude_regex_paths=[r"root(\[.*\])?\['uid'\]"])
Out[26]:
{'dictionary_item_added': [root[0]['key2']],
'dictionary_item_removed': [root[0]['key4']],
'values_changed': {"root[0]['key']": {'new_value': 'val2',
'old_value': 'val1'}}}
I am closing this ticket until we have a reproducible code that shows we have a bug.