seperman/deepdiff

Inconsistent Behavior with math_epsilon and ignore_order

movchan74 opened this issue · 1 comments

Describe the bug
When using DeepDiff, specifying both ignore_order=True and math_epsilon=0.01 parameters results in an inconsistency. The method issues a warning that math_epsilon will be ignored due to ignore_order being True, but the output suggests that math_epsilon is, in fact, considered.

To Reproduce
Steps to reproduce the behavior:

a = {'x': 0.001}
b = {'x': 0.0011}
print (deepdiff.DeepDiff(a, b, ignore_order=True)) # {'values_changed': {"root['x']": {'new_value': 0.0011, 'old_value': 0.001}}}

# Shows warning "math_epsilon will be ignored. It cannot be used when ignore_order is True." but still works
print (deepdiff.DeepDiff(a, b, ignore_order=True, math_epsilon=0.01)) # {}

Expected behavior
The expected behavior is ambiguous due to the warning message. If math_epsilon is meant to be ignored with ignore_order=True, the output should not consider math_epsilon. Conversely, if it is being considered despite the warning, the warning message might be misleading or erroneous.

OS, DeepDiff version and Python version:

  • OS: Ubuntu
  • Version: 20LTS
  • Python Version: 3.10
  • DeepDiff Version: 6.7.0

Additional context
The inconsistency between the warning message and the actual behavior of the method can lead to confusion about the effective application of the math_epsilon parameter in combination with ignore_order. Clarification or correction in either the documentation or the method's behavior would be beneficial.

Hi @movchan74
Thank you for reporting the inconsistency.

I have updated the docs to reflect that:

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.

For example:

>>> a = [{'x': 0.001}, {'y': 2.00002}]
>>> b = [{'x': 0.0011}, {'y': 2}]
>>> DeepDiff(a, b, ignore_order=True, math_epsilon=0.01)
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.
{'values_changed': {'root[1]': {'new_value': {'y': 2}, 'old_value': {'y': 2.00002}}, 'root[0]': {'new_value': {'x': 0.0011}, 'old_value': {'x': 0.001}}}}