8000 assert_all_equal doesn't structured arrays containing nan are equal to themselves · Issue #12346 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
assert_all_equal doesn't structured arrays containing nan are equal to themselves #12346
Closed
@hmaarrfk

Description

@hmaarrfk

xref: #12330 (comment)

The docs state that nan == nan in assert_array_equal
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.testing.assert_array_equal.html

Failer

import numpy as np
from numpy.testing import assert_array_equal
a = np.zeros(1, dtype='f8,f8')
a[0] = (np.nan, 0)
assert_array_equal(a, a)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-6-96868a4fad08> in <module>
----> 1 assert_array_equal(a, a)

/home/mark/git/numpy/numpy/testing/_private/utils.py in assert_array_equal(x, y, err_msg, verbose)
    871     __tracebackhide__ = True  # Hide traceback for py.test
    872     assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
--> 873                          verbose=verbose, header='Arrays are not equal')
    874 
    875 

/home/mark/git/numpy/numpy/testing/_private/utils.py in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf)
    795                                 verbose=verbose, header=header,
    796                                 names=('x', 'y'), precision=precision)
--> 797             raise AssertionError(msg)
    798     except ValueError:
    799         import traceback

AssertionError: 
Arrays are not equal

(mismatch 100.0%)
 x: array([(nan, 0.)], dtype=[('f0', '<f8'), ('f1', '<f8')])
 y: array([(nan, 0.)], dtype=[('f0', '<f8'), ('f1', '<f8')])

Workaround: don't use nan in structured array tests

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

      0