-
-
Notifications
You must be signed in to change notification settings - Fork 12k
Description
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:
- Don't. Tell dependencies to figure out a more robust way of handling this.
- Use some sort of
eval/execbased magic to build real function objects with the right signature Tracking issue for implementation of NEP-18 (__array_function__) #12028 (comment) - 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.