New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: np.equal.reduce no longer works with int and float #20929
Comments
@brisvag I am working on this |
Hmmmm... I am wondering if we shouldn't just call it a bug-fix. I am serious, I do not have an intuition for the following:
The result is always the same (except for pure object), as |
@seberg I see, I was not aware of the However, I'm a bit confused. Just to make sure I follow: the a = np.array(['x', 'y'])
b = np.stack([a, a, a], axis=1)
np.equal.reduce(b, axis=1) # (2,) array of bools, all True |
I don't think you are misunderstanding what reduce does, but I do think you are not realizing what it ends up doing :p. A reduce operation is defined by the following (roughly, how the start is handled depends and I think it makes the situation worse for
Now, the type of
and not:
might be surprising. But even then, what do you expect the intermediate result to be? Do you expect the same as |
This is very surprising indeed! So how is something like
Which would certainly fail? Or is casting to
I think I do expect that... which probably means reduce is just not the thing I should be using... |
Yes, well the new NumPy also rejects the thing for Note that the last one is really the same as |
I see, makes sense! Thanks for the explanation, things are clearer now, and it does indeed look like I was using a bug. To clarify, my actual use case was slightly more complex: a = ... # (n, 2) array
np.equal.reduce(a, axis=1) But since it's just |
If we consider this a bug fix (or even if not), it might be nice to add a test case for this, though. Even if someone changes behaviour in the future, it is better to have a test that notifies you that there was a change. I am not sure we have one. @soma2000-lang just in case you are interested in that. |
…tests tests were previously passing but updating numpy made them failed. See numpy/numpy#20929 For now all we want is the same behaviour as with standard np.ndarray
Hi, @seberg, @brisvag! New here! Just went through the discussion above, and I am assuming that this would require checking if I went through some similar looking tests and found this - numpy/numpy/core/tests/test_regression.py Lines 46 to 48 in abc26a3
Should I add a test in this function? Or could you please point out where this test should be added? Thanks! |
Thanks for having a look. I try to avoid adding regresssion tests, since they are even less structured than the rest of our tests. I think this class would be a good place: numpy/numpy/core/tests/test_umath.py Line 187 in fccb91f
|
Thank you for the quick reply, @seberg! |
Describe the issue:
In
1.22.1
the below code fails. However, it used to work in1.21.5
. It still works withobject
andbool
dtypes.Reproduce the code example:
Error message:
TypeError: No loop matching the specified signature and casting was found for ufunc equal
NumPy/Python version information:
1.22.1 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]
The text was updated successfully, but these errors were encountered: