You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's what you currently see if __array_function__ returns NotImplemented:
In [1]: import numpy as np
In [2]: class MyArray:
...: def __array_function__(*args, **kwargs):
...: return NotImplemented
...:
In [3]: np.sum(MyArray())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-c8a80bb1d37e> in <module>()
----> 1 np.sum(MyArray())
~/dev/numpy/numpy/core/overrides.py in public_api(*args, **kwargs)
149 relevant_args = dispatcher(*args, **kwargs)
150 return array_function_implementation_or_override(
--> 151 implementation, public_api, relevant_args, args, kwargs)
152
153 # TODO: remove this when we drop Python 2 support (functools.wraps
~/dev/numpy/numpy/core/overrides.py in array_function_implementation_or_override(implementation, public_api, relevant_args, args, kwargs)
108 raise TypeError('no implementation found for {} on types that implement '
109 '__array_function__: {}'
--> 110 .format(public_api, list(map(type, overloaded_args))))
111
112
TypeError: no implementation found for <function sum at 0x10e070bf8> on types that implement __array_function__: [<class '__main__.MyArray'>]
This error message should look something like this instead: TypeError: no implementation found for 'numpy.sum' on types that implement __array_function__: [<class '__main__.MyArray'>]
I think we will need to add a name parameter to array_function_override to do this properly. The best we could hope for with introspection is to use __module__ and __name__ to come up with something like numpy.core.fromnumeric.sum. This would be better what we currently have and could be a reasonable default, but we really don't want people reaching directly into internal modules like fromnumeric.
The text was updated successfully, but these errors were encountered:
Interestingly, it looks like IPython has special code for printing functions based on __module__ rather than repr() or str:
>>> np.sum
<function numpy.core.fromnumeric.sum>
We could probably reproduce this inside __array_function__. Along with manually updating the __module__ attribute this would probably give us what we want. Usage would look something like:
xref #12028
Here's what you currently see if
__array_function__
returnsNotImplemented
:This error message should look something like this instead:
TypeError: no implementation found for 'numpy.sum' on types that implement __array_function__: [<class '__main__.MyArray'>]
I think we will need to add a
name
parameter toarray_function_override
to do this properly. The best we could hope for with introspection is to use__module__
and__name__
to come up with something likenumpy.core.fromnumeric.sum
. This would be better what we currently have and could be a reasonable default, but we really don't want people reaching directly into internal modules likefromnumeric
.The text was updated successfully, but these errors were encountered: