Skip to content

ENH: Add annotations for remaining ndarray / generic non-magic methods#17372

Merged
charris merged 6 commits intonumpy:masterfrom
BvB93:from-numeric
Oct 5, 2020
Merged

ENH: Add annotations for remaining ndarray / generic non-magic methods#17372
charris merged 6 commits intonumpy:masterfrom
BvB93:from-numeric

Conversation

@BvB93
Copy link
Copy Markdown
Member

@BvB93 BvB93 commented Sep 23, 2020

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 for
    generic, 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 and keepdims is False -> a generic is returned.
    • out is None and (axis is not None or keepdims is True) -> a generic or ndarray 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 the fromnumeric annotations to their own stub file #17309), have been
    moved 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, have
    been moved from _ArrayOrScalarCommon to ndarray.

@BvB93
Copy link
Copy Markdown
Member Author

BvB93 commented Oct 5, 2020

Any comments?

@charris charris merged commit 9ebd2bf into numpy:master Oct 5, 2020
@charris
Copy link
Copy Markdown
Member

charris commented Oct 5, 2020

Thanks @BvB93 . No comments, but 12 days old, so in it goes.

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.

2 participants