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
ufuncs on object arrays should call __array_ufunc__ if it exists on the wrapped objects #15479
Comments
Note that Now, you could add a "fallback" or initial path, that tests whether the "element" is an array like and thus might But: I am not sure we should... Note that you get the same result for NumPy arrays (with the exception that |
OK, probably the simplest reproduction is:
Of course I have a use-case for this, but it's pretty non-canonica). I'm not entirely sure it's worth the trouble :) |
There is another problem I ran into while trying Well, it was possibly a knee jerk reaction, but I might need a bit more convincing :). Although, I admit that an object exporting |
I have an issue that might be similar. I was trying to get import numpy as np
class dummy(np.lib.mixins.NDArrayOperatorsMixin):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
return 'GO!'
print(dummy() + 1) # GO!
print(dummy() + np.float64(1)) # GO!
print(dummy() + np.timedelta64(1, 'D')) # GO!
print(np.add(dummy(), np.timedelta64(1, 'D'))) # GO!
print(np.array(dummy()) + np.float64(1)) # GO!
print(np.array(dummy()) + np.timedelta64(1, 'D')) # error I am puzzled since when it works with |
The one is also because the object loop exists but isn't picked:
That is a small bug in the legacy promotion step (object should win out against datetimes). |
Reproducing code example:
Here's my dummy class that implement
__array_ufunc__
for ufuncs and arithmetic:It works fine on its own, and scalar arithmetic works fine when wrapped in a dtype=object numpy.array. But calling ufuncs on the object array raises a strange TypeError:
Error message:
I'm not sure what exactly is going on, but it seems that we don't call actual ufuncs on the elements of
dtype=object
arrays, and instead only look for methods.Numpy/Python version information:
1.17.5 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0]
The text was updated successfully, but these errors were encountered: