Skip to content

array_function_dispatch() breaks inspect.getargspec/getfullargspec #12225

@shoyer

Description

@shoyer

xref #12028

Even though assuredly this isn't really guaranteed by our API, introspection into NumPy function arguments appears to be used by a number of our dependencies. Unfortunately, although inspect.signature has a follow_wrapped argument this isn't the case for inspect.getfullargspec or the old inspect.getargspec (still used for Python 2.7 compatibility in many cases).

Behavior on master:

>>> inspect.getfullargspec(np.sum)
FullArgSpec(args=[], varargs='args', varkw='kwargs', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})

Behavior with the released version of NumPy:

>>> inspect.getfullargspec(np.sum)
FullArgSpec(args=['a', 'axis', 'dtype', 'out', 'keepdims'], varargs=None, varkw=None, defaults=(None, None, None, <class 'numpy._globals._NoValue'>), kwonlyargs=[], kwonlydefaults=None, annotations={})

This results in test failures in dask (dask/dask#4111) and is my best guess for pandas test failures (pandas-dev/pandas#23172).

We have a few options for fixing this:

  1. Don't. Tell dependencies to figure out a more robust way of handling this.
  2. Use some sort of eval/exec based magic to build real function objects with the right signature Tracking issue for implementation of NEP-18 (__array_function__) #12028 (comment)
  3. Stop using a decorator in favor of writing functions with explicit signatures.

(1) seems quite unfriendly to users. (3) would result in a lot of more boilerplate code in NumPy and would break extensibility.

(2) might have a negative impact on import performance, but may be our best bet.

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