array_equal(a, b, equal_nan=True) throws errors for array with non-numeric values
See original GitHub issueUsing the newly added (#16128) np.array_equal
keyword argument equal_nan
fails when the values of the passed array aren’t accepted by np.isnan
. This occurs for values like strings.
Reproducing code example:
import numpy as np
np.array_equal(
np.array(list("abc")), np.array(list("abc")), equal_nan=True
)
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in array_equal
File "/Users/isaac/github/numpy/numpy/core/numeric.py", line 2381, in array_equal
a1nan, a2nan = isnan(a1), isnan(a2)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Numpy/Python version information:
This occurs on both master and 1.19.0rc1
1.20.0.dev0+3f11db4 3.7.7 (default, Apr 25 2020, 15:09:12)
[Clang 11.0.3 (clang-1103.0.32.59)]
1.19.0rc1 3.7.7 (default, May 6 2020, 04:59:01)
[Clang 4.0.1 (tags/RELEASE_401/final)]
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (12 by maintainers)
Top Results From Across the Web
ARRAY_EQUAL - L3HarrisGeospatial.com
The ARRAY_EQUAL function is a fast way to compare data for equality in situations where the index of the elements that differ are...
Read more >numpy.array_equal — NumPy v1.24 Manual
Returns True if two arrays are element-wise equal within a tolerance. array_equiv. Returns True if input arrays are shape consistent and all elements...
Read more >Comparing numpy arrays containing NaN - Stack Overflow
I just added np.testing.assert_equal(a,b) in my unittest, and if it raises the exception, the test fails (no error), and I ...
Read more >array_equals
With this function you can check to see if two arrays are equal (equivalent or the ... which will not check to see...
Read more >How can I set a matrix value to equal a non-numeric coordinate?
For example, if part of a matrix equals 3, I want that coordinate to be (a,b). Then I want to be able to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, lets ignore
object
here for now, its trickier.String I think we can just propose, may need a bit of discussion (or maybe digging up the old discussion when we added bools and ints). We have no string ufuncs (this is mainly because you have to set the output string length correctly, which made, also me, always think that its tricky). The other point is that string promotion is still broken (weakly typed) which could lead to strange things (I would like to move that concat + string promotion deprecation forward!). But this is a unary ufunc, with boolean output that is always
False
, so neither of those issues would stand in the way.okay thanks @seberg for the guidance ! So @ivirshup if you are interested in proposing something for string support for isnan that would be great here. Maybe some of the discussion topics that @seberg mentioned may be : https://github.com/numpy/numpy/pull/12988 and the xref’d issues.
Given the current discussion, I think we should close the current PR #16378 .