assert_array_equal does not compare NaNs as numbers when dtype is object
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
OS: macOS Sierra (10.12.5)
Python version: 2.7.12
numpy version: 1.13.0
I notice that numpy.testing.assert_array_equal should compare NaNs as numbers unlike elsewhere in numpy, which makes sense to me. I verify this with the following test:
>>> import numpy.testing as npt
>>> import numpy as np
>>> a = np.array([1, 2, np.nan])
>>> npt.assert_array_equal(a, a)
However, this does not work with arrays that have dtype object:
>>> b = np.array([1, 2, 'a', np.nan], dtype=object)
>>> npt.assert_array_equal(b, b)
AssertionError:
Arrays are not equal
(mismatch 25.0%)
x: array([1, 2, 'a', nan], dtype=object)
y: array([1, 2, 'a', nan], dtype=object)
Is this the desired behaviour? The only workaround in my case is to cast the array as dtype str.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at numpy.testing.assert_array_equal and reproduce the two examples from the issue, comparing regular and object-dtype arrays containing NaN. Trace the object-array comparison path and add a regression test showing the intended NaN comparison behavior, then run the relevant NumPy testing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 43/100