-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Conversation
Newly annotated functions: * `clip` * `sum` * `all` * `any` * `cumsum` * `ptp` * `amax` * `amin`
There was a problem hiding this 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 |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
numpy/__init__.pyi
Outdated
@overload | ||
def clip( | ||
a: _Number, | ||
a_min: Optional[ArrayLike], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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.
Raise an exception if `a_min` and `a_max` are both `None`
Thanks for the feedback everyone! |
LGTM, thanks @BvB93. |
This pull request adds annotations to eight functions from
numpy.core.fromgeneric
:clip()
sum()
all()
any()
cumsum()
ptp()
amax()
amin()