Skip to content

Misleading __array_ufunc__ error #9079

@eric-wieser

Description

@eric-wieser

Here's a very simple __array_ufunc__, which is likely to be one of the first tests people try:

class foo(np.ndarray):
     def __array_ufunc__(self, *args, **kwargs):
         print(args, kwargs)
         return super().__array_ufunc__(*args, **kwargs)

Unfortunately, the error given is a little unhelpful:

>>> a = np.array(1).view(foo)
>>> a + a
(<ufunc 'add'>, '__call__', foo(1), foo(1)) {}
(<ufunc 'add'>, '__call__', foo(1), foo(1)) {}
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-24070be0e9db> in <module>()
----> 1 a + a

TypeError: operand type(s) do not implement __array_ufunc__(<ufunc 'add'>, '__call__', foo(1), foo(1)): 'foo', 'foo'

Some kind of hint that ndarray.__array_ufunc__ was not able to handle things either might be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions