Skip to content

assert_allclose(..., equal_nan=False) doesn't raise an assertion error #8145

Closed
@akaihola

Description

@akaihola

np.testing.assert_allclose is supposed to raise an AssertionError when comparing two NaN values with equal_nan=False. However, it succeeds without exceptions for both scalars and vectors.

np.allclose(..., equal_nan=False) does work as documented as seen below, but for assert_allclose the behavior is inconsistent with both the documentation and allclose.

>>> import numpy as np
>>> a = np.array([42.0, np.nan])
>>> b = np.array([42.0, np.nan])
>>> np.allclose(np.nan, np.nan, equal_nan=True)
True
>>> np.allclose(a, b, equal_nan=True)
True
>>> np.testing.assert_allclose(np.nan, np.nan, equal_nan=True)
>>> np.testing.assert_allclose(a, b, equal_nan=True)
>>> np.allclose(np.nan, np.nan, equal_nan=False)
False
>>> np.allclose(a, b, equal_nan=False)
False
>>> # These two should raise an AssertionError:
>>> np.testing.assert_allclose(np.nan, np.nan, equal_nan=False)
>>> np.testing.assert_allclose(a, b, equal_nan=False)

I tested this with master branch commit b0a6e55 from today (2016-10-12). I'm running Python 3.5.1 on Fedora 23.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions