Skip to content

Commit 01210c8

Browse files
committed
updating docs for Inconsistent Behavior with math_epsilon and
ignore_order. Fixes #431
1 parent b5d1484 commit 01210c8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

deepdiff/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def _group_by_sort_key(x):
231231
self.significant_digits = self.get_significant_digits(significant_digits, ignore_numeric_type_changes)
232232
self.math_epsilon = math_epsilon
233233
if self.math_epsilon is not None and self.ignore_order:
234-
logger.warning("math_epsilon will be ignored. It cannot be used when ignore_order is True.")
234+
logger.warning("math_epsilon in conjunction with ignore_order=True is only used for flat object comparisons. Custom math_epsilon will not have an effect when comparing nested objects.")
235235
self.truncate_datetime = get_truncate_datetime(truncate_datetime)
236236
self.number_format_notation = number_format_notation
237237
if verbose_level in {0, 1, 2}:

tests/test_diff_text.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,4 +2008,3 @@ class Bar(PydanticBaseModel):
20082008
diff = DeepDiff(t1, t2)
20092009
expected = {'values_changed': {'root.stuff[0].thing': {'new_value': 2, 'old_value': 1}}}
20102010
assert expected == diff
2011-

tests/test_ignore_order.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,32 @@ def test_ignore_order_and_group_by4(self):
897897

898898
assert expected == diff
899899

900+
def test_math_epsilon_when_ignore_order_in_dictionary(self):
901+
a = {'x': 0.001}
902+
b = {'x': 0.0011}
903+
diff = DeepDiff(a, b, ignore_order=True)
904+
assert {'values_changed': {"root['x']": {'new_value': 0.0011, 'old_value': 0.001}}} == diff
905+
906+
diff2 = DeepDiff(a, b, ignore_order=True, math_epsilon=0.01)
907+
assert {} == diff2
908+
909+
def test_math_epsilon_when_ignore_order_in_list(self):
910+
a = [0.001, 2]
911+
b = [2, 0.0011]
912+
diff = DeepDiff(a, b, ignore_order=True)
913+
assert {'values_changed': {'root[0]': {'new_value': 0.0011, 'old_value': 0.001}}} == diff
914+
915+
diff2 = DeepDiff(a, b, ignore_order=True, math_epsilon=0.01)
916+
assert {} == diff2
917+
918+
def test_math_epsilon_when_ignore_order_in_nested_list(self):
919+
a = [{'x': 0.001}, {'y': 2.00002}]
920+
b = [{'x': 0.0011}, {'y': 2}]
921+
922+
diff = DeepDiff(a, b, ignore_order=True, math_epsilon=0.01)
923+
expected = {'values_changed': {'root[0]': {'new_value': {'x': 0.0011}, 'old_value': {'x': 0.001}}, 'root[1]': {'new_value': {'y': 2}, 'old_value': {'y': 2.00002}}}}
924+
assert expected == diff
925+
900926

901927
class TestCompareFuncIgnoreOrder:
902928

0 commit comments

Comments
 (0)