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

MAINT: Annotate missing attributes of np.number subclasses #19344

Merged
merged 2 commits into from
Jun 25, 2021

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Jun 25, 2021

closes #19339

A number of np.number subclass attributes were previously absent from the stub files.
This PR fixes aforementioned issue, adding annotations for the following properties and methods:

  • integer.numerator & denominator
  • integer.__round__ & floating.__round__
  • floating.as_integer_ratio
  • float64.__getnewargs__ & complex128.__getnewargs__
  • float64.is_integer, hex, fromhex, __trunc__ & __getformat__
  • float64.__ceil__ & float64.__floor__ (python >= 3.9 only)

@BvB93 BvB93 added this to the 1.21.1 release milestone Jun 25, 2021
@@ -3313,6 +3327,21 @@ class floating(inexact[_NBit1]):
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
) -> float: ...
def tolist(self) -> float: ...
def is_integer(self: float64) -> bool: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

A number of these methods are only available to np.float64 (xref #13375).

* `integer.numerator` & `denominator`
* `integer.__round__` & `floating.__round__`
* `floating.as_integer_ratio`
* `float64.__getnewargs__` / `complex128.__getnewargs__`
* `float64.is_integer`, `hex`, `fromhex`, `__trunc__` & `__getformat__`
* `float64.__ceil__` & `float64.__floor__` (python >= 3.9 only)
Comment on lines +3164 to +3165
@property
def denominator(self) -> L[1]: ...
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'd argue that denominator returning a builtins.int instance is somewhat concerning, especially for np.uint64.

@charris charris merged commit 55b0550 into numpy:main Jun 25, 2021
@charris
Copy link
Member

charris commented Jun 25, 2021

Thanks Bas.

@BvB93 BvB93 deleted the generic-attr branch June 25, 2021 20:04
@BvB93 BvB93 removed the 09 - Backport-Candidate PRs tagged should be backported label Jun 25, 2021
@BvB93 BvB93 removed this from the 1.21.1 release milestone Jun 25, 2021
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.

Mypy complains if I want to round np.int_ or np.float_
2 participants