You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem was using math.isclose which produces false results:
def are_different(first, second, tolerance, absolute_tolerance=None):
"""Check if 2 values are different.
In case of numerical values, the tolerance is used to check if the values
are different.
In all other cases, the difference is straight forward.
"""
if first == second:
# values are same - simple case
return False
first_is_nan, second_is_nan = bool(first != first), bool(second != second)
if first_is_nan or second_is_nan:
# two 'NaN' values are not different (see issue #114)
return not (first_is_nan and second_is_nan)
elif isinstance(first, num_types) and isinstance(second, num_types):
# two numerical values are compared with tolerance
return not math.isclose(
first,
second,
rel_tol=tolerance or 0,
abs_tol=absolute_tolerance or 0,
)
# we got different values
return True
However, since python3 has no maximum integer, I think a general solution for allowing requiring exact equality between integers would require a change to the library. I was looking at the same code in wondering how to dictdiffer should compare Decimal(1.99) to Decimal("1.99"), and after looking further into the subclasses of number.Number came to the conclusion that tolerating floating-point imprecision is appropriate only when both operands are floats.
This is a judgement call for the maintainers that is arguably a breaking change, but I think it's consistent with the docstring and all the existing tests and that the alternative is a can of worms with too many edge cases. Proposed #183
python3.8, python3.9
Test code:
Return empty list.
The problem was using math.isclose which produces false results:
Test example:
The text was updated successfully, but these errors were encountered: