Skip to content

Commit

Permalink
fixes #509
Browse files Browse the repository at this point in the history
  • Loading branch information
seperman committed Dec 15, 2024
1 parent 5120230 commit f1d87e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions deepdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,17 @@ def _diff_dict(
t1_clean_to_keys = t2_clean_to_keys = None

t_keys_intersect = t2_keys & t1_keys
t_keys_union = t2_keys | t1_keys
t_keys_added = t2_keys - t_keys_intersect
t_keys_removed = t1_keys - t_keys_intersect

if self.threshold_to_diff_deeper:
if len(t_keys_union) > 1 and len(t_keys_intersect) / len(t_keys_union) < self.threshold_to_diff_deeper:
if self.exclude_paths:
t_keys_union = {f"{level.path()}[{repr(key)}]" for key in (t2_keys | t1_keys)}
t_keys_union -= self.exclude_paths
t_keys_union_len = len(t_keys_union)
else:
t_keys_union_len = len(t2_keys | t1_keys)
if t_keys_union_len > 1 and len(t_keys_intersect) / t_keys_union_len < self.threshold_to_diff_deeper:
self._report_result('values_changed', level, local_tree=local_tree)
return

Expand Down
4 changes: 4 additions & 0 deletions tests/test_diff_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,10 @@ def test_skip_path2_reverse(self):
ddiff = DeepDiff(t2, t1, exclude_paths={"root['ingredients']"})
assert {} == ddiff

def test_exclude_path_when_prefix_of_exclude_path_matches1(self):
diff = DeepDiff({}, {'foo': '', 'bar': ''}, exclude_paths=['foo', 'bar'])
assert not diff

def test_include_path3(self):
t1 = {
"for life": "vegan",
Expand Down

0 comments on commit f1d87e9

Please sign in to comment.