ENH: Add annotations for remaining ndarray
/ generic
non-magic methods
#17372
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds annotations for all remaining
ndarray
/generic
non-magic methods.Fortunately, most of these methods were already typed in their function-based counterpart from
np.core.fromnumeric
, so they could be copied over with minor alterations.A few notes and observations:
The annotations are mostly geared towards
ndarray
. While they're not necessarily incorrect forgeneric
, the signatures are generally speaking a bit too broad. Something to refine in a follow up.The overload pattern of
ndarray.all()
is a very common one here:out is None
,axis is None
andkeepdims is False
-> ageneric
is returned.out is None
and(axis is not None or keepdims is True)
-> ageneric
orndarray
is returned.out is not None
->out
is returned. One of the few cases where we can safelly use a typevar.A few annotations, that were recently moved to
np.core.fromnumeric
(MAINT: Move thefromnumeric
annotations to their own stub file #17309), have beenmoved back to the main
__init__.pyi
file, as they were needed for the newly annotated methods.A number of methods, that are either just plain unavailable to
generic
or require a>=1D
array, havebeen moved from
_ArrayOrScalarCommon
tondarray
.