Skip to content
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

ENH: Added annotations to 8 functions from np.core.fromnumeric #16647

Merged
merged 4 commits into from
Jun 23, 2020

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Jun 20, 2020

This pull request adds annotations to eight functions from numpy.core.fromgeneric:

  • clip()
  • sum()
  • all()
  • any()
  • cumsum()
  • ptp()
  • amax()
  • amin()

Newly annotated functions:
* `clip`
* `sum`
* `all`
* `any`
* `cumsum`
* `ptp`
* `amax`
* `amin`
Copy link
Member

@person142 person142 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment about clip, but looks good.

_ArrayLikeBool = Union[
_Bool,
Sequence[_Bool],
ndarray
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon we will have ndarray generic over dtype...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I feel this is gona be a biiiiiig help.

@overload
def clip(
a: _Number,
a_min: Optional[ArrayLike],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a_min and a_max can't both be None, so you could get more specific here with even more overloads.

Copy link
Member Author

@BvB93 BvB93 Jun 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 4d3641e.
mypy's error for assigning NoReturn are, unfortunately, not the most descriptive, but it will have to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you do better, by defining:

    a_min: ArrayLike,
    a_max: Optional[ArrayLike],

and an overload,

    a_min: None,
    a_max: ArrayLike,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually hadn't considered that; good idea.
Implemented in 9e59f57.

Bas van Beek added 3 commits June 20, 2020 21:57
Raise an exception if `a_min` and `a_max` are both `None`
@BvB93
Copy link
Member Author

BvB93 commented Jun 22, 2020

Thanks for the feedback everyone!
If there are no more questions and/or comments then I'd propose to merge it by tomorrow.

@person142 person142 merged commit dda8c85 into numpy:master Jun 23, 2020
@person142
Copy link
Member

LGTM, thanks @BvB93.

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.

None yet

3 participants