Skip to content

Attributes on the objects dispatched via _ArrayFunctionDispatcher #24019

@adrinjalali

Description

@adrinjalali

Steps to reproduce:

In numpy>=1.25, this is the behavior:

>>> import numpy as np
>>> type(np.mean)
<class 'numpy._ArrayFunctionDispatcher'>
>>> import inspect
>>> inspect.isfunction(np.mean)
False
>>> inspect.ismethod(np.mean)
False
>>> from numpy import _ArrayFunctionDispatcher
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name '_ArrayFunctionDispatcher' from 'numpy' (/home/adrin/miniforge3/envs/skops/lib/python3.11/site-packages/numpy/__init__.py)

I would think inspect.isfunction(np.mean) should return True, maybe?

Also, it's odd that the type(np.mean) returns something which cannot be imported, and the actual import is from numpy.core._multiarray_umath import _ArrayFunctionDispatcher.

Ended up observing this since our dispatch mechanism in skops which was dispatching ufunc was ignored since these are no more ufuncs (I think they were before?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions