Open
Description
Reproducing code example:
Here's my dummy class that implement __array_ufunc__
for ufuncs and arithmetic:
import numpy as np
class Wrapper(np.lib.mixins.NDArrayOperatorsMixin):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
return 'yes'
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:
print(Wrapper() + 1) # 'yes'
print(np.sqrt(Wrapper())) # 'yes'
print(np.array(Wrapper()) + 1) # 'yes'
print(np.sqrt(np.array(Wrapper()))) # errors
Error message:
AttributeError Traceback (most recent call last)
AttributeError: 'Wrapper' object has no attribute 'sqrt'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-59-ace91090b167> in <module>()
8 print(np.sqrt(Wrapper())) # 'yes'
9 print(np.array(Wrapper()) + 1) # 'yes'
---> 10 print(np.sqrt(np.array(Wrapper()))) # errors
TypeError: loop of ufunc does not support argument 0 of type Wrapper which has no callable sqrt method
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]