Skip to content

MAINT,ENH: Rename all dispatchers as well as possible #21667

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

Closed
wants to merge 3 commits into from

Conversation

seberg
Copy link
Member

@seberg seberg commented Jun 4, 2022

This is a bit of a call and various decisions could be made.
In some cases, I simply duplicated dispatchers to get the rigth name
(there is no other way to rename the function).

In other cases, I attempted to find a somewhat decent name (without
underscore) that at least gives a better idea than having
_dispatcher in there.
I tried to standardize the two most common ones to unary_operation
and binary_operation.

It may be possible to auto-copy the function and replace the name
in the decorator. In general (if there is a custom decorator), I think
using the same name is probably best.

I do not have a strong opinion about the cases where dispatchers are
used multiple times though. E.g. when to duplicate and when not.


As a reminder, this fixes (mostly) the problem that:

np.histogram(asdf=3)

gives:

TypeError: _histogram_dispatcher() got an unexpected keyword argument 'asdf'

which I think is potentially confusing to users. It thus mostly addreses gh-21647.

@shoyer since this was originally your work, could you have a look/review this?

(I am happy about other ideas, or at least reducing it to only fix places where the dispatcher is defined directly before the function.)

The following symbols have dispatcher names that do not match and are not either unary_operation or binary_operation:

numpy.core.fromnumeric round_ around
numpy.core.fromnumeric product prod
numpy.core.fromnumeric cumproduct cumprod
numpy.core.fromnumeric sometrue any
numpy.core.fromnumeric alltrue all
numpy.core.defchararray count find_or_count
numpy.core.defchararray find find_or_count
numpy.core.defchararray index find_or_count
numpy.core.defchararray rfind find_or_count
numpy.core.defchararray rindex find_or_count
numpy.core.defchararray rpartition partition
numpy.lib.type_check iscomplex is_type
numpy.lib.type_check isreal is_type
numpy.lib.type_check iscomplexobj is_type
numpy.lib.type_check isrealobj is_type
numpy.lib.shape_base hsplit hvdsplit
numpy.lib.shape_base vsplit hvdsplit
numpy.lib.shape_base dsplit hvdsplit
numpy.fft._pocketfft ifft fft
numpy.fft._pocketfft rfft fft
numpy.fft._pocketfft irfft fft
numpy.fft._pocketfft hfft fft
numpy.fft._pocketfft ihfft fft
numpy.fft._pocketfft ifftn fftn
numpy.fft._pocketfft fft2 fftn
numpy.fft._pocketfft ifft2 fftn
numpy.fft._pocketfft rfftn fftn
numpy.fft._pocketfft rfft2 fftn
numpy.fft._pocketfft irfftn fftn
numpy.fft._pocketfft irfft2 fftn

seberg added 2 commits June 9, 2022 20:49
Median does not currently support Datetimes.  This is because
`mean` does not support datetimes.
The reason for `mean` not supporting datetimes, is that it is
(understandibly) written as `(a + b)/2`, but datetimes cannot
be added so that we would have to use a different scheme, such as
`a + (b - a) / 2`.
Unlike Median, the interpolation formula used by quantile/percentile
does support Datetimes just fine, so this also adds basic tests for
that.
Due to the integral nature, times suffer round-off errors that seem
not ideal.  This is an issue, but distinct from the NaT one?
@charris
Copy link
Member

charris commented Jun 10, 2022

@seberg Needs a rebase (already :)

This is a bit of a call and various decisions could be made.
In some cases, I simply duplicated dispatchers to get the rigth name
(there is no other way to rename the function).

In other cases, I attempted to find a somewhat decent name (without
underscore) that at least gives a better idea than having
`_dispatcher` in there.
I tried to standardize the two most common ones to `unary_operation`
and `binary_operation`.

It may be possible to auto-copy the function and replace the name
in the decorator.  In general (if there is a custom decorator), I think
using the same name is probably best.

I do not have a strong opinion about the cases where dispatchers are
used multiple times though.  E.g. when to duplicate and when not.
@seberg seberg force-pushed the array-dispatcher-name-cleanup-start branch from 56de6b3 to e8a110f Compare June 10, 2022 19:37
@mhvk
Copy link
Contributor

mhvk commented Jun 11, 2022

Bit from the sidelines, but would it not be simpler to try/except the call to the dispatcher and on error change the name of the function in the exception message? (or even just append a message noting the function that called the dispatcher). As is, I'm not sure that the reduction in code readability is worth the better error message.

@seberg
Copy link
Member Author

seberg commented Jun 11, 2022

Hmmm, I had half discarded that thought, because the inspection seemed a bit annoying. However, we only have to inspect errors originating in the "dispatcher" itself, and those are much less likely to get a bunch of complicated errors their way, so the inspection is a bit less bad.

(There could be rare cases where there is a TypeError not originating from the signature mismatch, but probably really rare.)

Let me try that, I think you are likely right and that is just good.

@seberg
Copy link
Member Author

seberg commented Jun 11, 2022

OK, lets consider the alternative in gh-21731 and close this. Thanks for the input!

@seberg seberg closed this Jun 11, 2022
@seberg seberg deleted the array-dispatcher-name-cleanup-start branch June 11, 2022 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants