Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Behavior with math_epsilon and ignore_order #431

Closed
movchan74 opened this issue Nov 10, 2023 · 1 comment
Closed

Inconsistent Behavior with math_epsilon and ignore_order #431

movchan74 opened this issue Nov 10, 2023 · 1 comment

Comments

@movchan74
Copy link

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.

@seperman
Copy link
Owner

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}}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants