-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Defining overrides for aliased NumPy functions in NumPy #13877
Description
There are handful of NumPy functions that are implemented as aliases of other NumPy function. These include at least min, max, round (non-ufuncs) and abs (an alias of the np.absolute ufunc):
Lines 92 to 93 in b4105bf
| from .fromnumeric import amax as max, amin as min, round_ as round | |
| from .numeric import absolute as abs |
Because np.min is defined as amin, that's also how you have to override the function with __array_function__. This leads to surprising behaviors for libraries like dask, which wrote its __array_function__ method to alias numpy functions to dask/cupy functions of the same name: because dask.array.amin does not exist, numpy.min (an alias for numpy.amin) doesn't work: dask/dask#5031
Things we could do about this on the NumPy side:
- Nothing -- the error message is clear enough. Dask can implement
amin/amaxeasily enough. - Define separate wrapper functions, so they can be overridden by the name users specify. Interestingly this is already the case for
round_, which is a wrapper aroundaround.
I think option (2) makes sense for min, max and round. It's not a great option for abs, since that would mean it no longer goes through __array_ufunc__.