-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Implement ArrayFunctionDispatcher.__get__
#23039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ArrayFunctionDispatcher.__get__
ArrayFunctionDispatcher.__get__
While functions should not normally need this, Python functions do provide it (C functions do not, but we are a fatter object anyway). By implementing `__get__` we also ensure that `inspect.isroutine()` passes. And by that we ensure that Sphinx considers these a `py:function:` role. Closes numpygh-23032
a814bec
to
c7b1269
Compare
I can confirm that downloading the
|
Thanks @seberg this is a very clean fix |
The behavior in NumPy slightly have changed with [1], and the type of NumPy functions (like np.mean) isn't 'function' but 'np._ArrayFunctionDispatcher'. This makes some test fail. This commit makes accepting 'np._ArrayFunctionDispatcher' as an allowed type [1]: numpy/numpy#23039
Hi, it seems like this PR changed the type of NumPy functions from We have seen this changed of behavior via scikit-learn/scikit-learn#25202 (see this log) For now, we have this temporary fix: scikit-learn/scikit-learn#25498 PS: I do not know how the tone of this message was like, but I was probably annoyed by other reasons when writing it. Sorry for the annoyance. |
I would might suggest to spell it as Yes, the previous PR changed it for much faster dispatching with keyword arguments especially. Does this break anything important to users (i.e. in released versions?) or just a small thing? At least from my perspective there would have to be a decent amount of fallout to change it back, since it just mean unnecessary overhead. Note that the current logic also seems to be missing the built-in (C defined) methods in theory. (NumPy effectively doesn't have those, because since 1.17 all functions were wrapped into Python functions unless opted out). |
For now, nothing breaks in our release version, it's more that I wanted to raise awareness about this change of behavior which impact downstream maintainers, such as scikit-learn's. I do not suggest nor demand making changes (I have not spent time understanding NumPy internals in this regards), but would like to know if you want to address it in NumPy so that type inspection for (some) NumPy objects remains unchanged. 🙂 |
I do not think there is a way to guarantee that you get a Python function back other than wrapping everything or reverting. Meaning you would buy it at a cost of probably something like 50-100ns per call. |
OK, then my interjection is irrelevant and can be ignored. |
While functions should not normally need this, Python functions do provide it (C functions do not, but we are a fatter object anyway).
By implementing
__get__
we also ensure thatinspect.isroutine()
passes. And by that we ensure that Sphinx considers these apy:function:
role.Closes gh-23032