Closed
Description
When using assert_almost_equal
for floats I get different results when using arrays.
This can be seen by this code:
>>> from numpy.testing import assert_almost_equal
>>> assert_almost_equal(1.01, 1.02, 2)
AssertionError:
Arrays are not almost equal to 2 decimals
ACTUAL: 1.01
DESIRED: 1.02
>>> assert_almost_equal([1.01, 1.0], [1.02, 1.0], 2)
>>>
Looking at utils.py
the behavior can be explained:
Float
When comparing using simple float values, this is the if
that checks if values are equal:
if round(abs(desired - actual), decimal) != 0 :
https://github.com/numpy/numpy/blob/master/numpy/testing/utils.py#L489
Array
But when comparing using arrays:
return around(z, decimal) <= 10.0**(-decimal)
https://github.com/numpy/numpy/blob/master/numpy/testing/utils.py#L838
Making the same assert behave in different ways.
Metadata
Metadata
Assignees
Labels
No labels