Skip to content

numpy.array_equal() returns False on apparently identical arrays with NaN values #9229

@cwfinn

Description

@cwfinn

OS: macOS Sierra (10.12.5)
Python version: 2.7.12
numpy version: 1.13.0

Passing np.array_equal() two apparently identical arrays containing NaN values returns False. See the following example replicating this issue:

>>> a = np.array([1, 2, np.nan])
>>> np.array_equal(a, a)
False

It would make sense to me if this returned True, though I understand that the following comparison returns False by definition:

>>> np.nan == np.nan
False

I presume this is related to changes in np.equal and np.not_equal. If this is the desired behaviour, I wonder if it might be more helpful for the element-wise comparison to raise an exception on encountering NaN comparisons, as this has caused unit test failures for me and took a while to track down.

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