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

MAINT: make assert_allclose behavior on nans match pre 1.12 #8184

Merged
merged 1 commit into from
Oct 20, 2016

Conversation

person142
Copy link
Member

Before:

>>> import numpy as np
>>> np.__version__
'1.11.2'
>>> np.testing.assert_array_equal(np.nan, np.nan)
>>> np.testing.assert_array_almost_equal(np.nan, np.nan)
>>> np.testing.assert_array_less(np.nan, np.nan)
>>> np.testing.assert_allclose(np.nan, np.nan)

Now:

>>> np.__version__
'1.12.0.dev0+6da5f00'
>>> np.testing.assert_array_equal(np.nan, np.nan)
>>> np.testing.assert_array_almost_equal(np.nan, np.nan)
>>> np.testing.assert_array_less(np.nan, np.nan)
>>> np.testing.assert_allclose(np.nan, np.nan)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Josh/Projects/numpy-dev/python3/numpy/numpy/testing/utils.py", line 1388, in assert_allclose
    verbose=verbose, header=header, equal_nan=equal_nan)
  File "/Users/Josh/Projects/numpy-dev/python3/numpy/numpy/testing/utils.py", line 773, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=1e-07, atol=0

(mismatch 100.0%)
 x: array(nan)
 y: array(nan)

Admittedly np.assert_allclose(np.nan, np.nan) raising seems more natural, but the changes make some old tests fail. For context see:

scipy/scipy#6696
scipy/scipy#6697

@rgommers
Copy link
Member

Admittedly np.assert_allclose(np.nan, np.nan) raising seems more natural

Only from a "this is how floating point numbers work" point of view. If you compare a test result with expected values, then the nans in the given expected values are there on purpose and should compare equal for testing purposes.

@charris charris merged commit 9cb5ac6 into numpy:master Oct 20, 2016
@charris
Copy link
Member

charris commented Oct 20, 2016

Thanks @person142 .

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

Successfully merging this pull request may close these issues.

None yet

3 participants