Skip to content

Commit 85841fc

Browse files
author
Bas van Beek
committed
MAINT: Annotate missing attributes of np.number subclasses
* `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)
1 parent f4bd901 commit 85841fc

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

numpy/__init__.pyi

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,15 @@ else:
31593159
]
31603160

31613161
class integer(number[_NBit1]): # type: ignore
3162+
@property
3163+
def numerator(self: _ScalarType) -> _ScalarType: ...
3164+
@property
3165+
def denominator(self) -> L[1]: ...
3166+
@overload
3167+
def __round__(self, ndigits: None = ...) -> int: ...
3168+
@overload
3169+
def __round__(self: _ScalarType, ndigits: SupportsIndex) -> _ScalarType: ...
3170+
31623171
# NOTE: `__index__` is technically defined in the bottom-most
31633172
# sub-classes (`int64`, `uint32`, etc)
31643173
def item(
@@ -3232,6 +3241,10 @@ class timedelta64(generic):
32323241
__value: Union[None, int, _CharLike_co, dt.timedelta, timedelta64] = ...,
32333242
__format: Union[_CharLike_co, Tuple[_CharLike_co, _IntLike_co]] = ...,
32343243
) -> None: ...
3244+
@property
3245+
def numerator(self: _ScalarType) -> _ScalarType: ...
3246+
@property
3247+
def denominator(self) -> L[1]: ...
32353248

32363249
# NOTE: Only a limited number of units support conversion
32373250
# to builtin scalar types: `Y`, `M`, `ns`, `ps`, `fs`, `as`
@@ -3301,7 +3314,8 @@ uint0 = unsignedinteger[_NBitIntP]
33013314
uint = unsignedinteger[_NBitInt]
33023315
ulonglong = unsignedinteger[_NBitLongLong]
33033316

3304-
class inexact(number[_NBit1]): ... # type: ignore
3317+
class inexact(number[_NBit1]): # type: ignore
3318+
def __getnewargs__(self: inexact[_64Bit]) -> Tuple[float, ...]: ...
33053319

33063320
_IntType = TypeVar("_IntType", bound=integer)
33073321
_FloatType = TypeVar('_FloatType', bound=floating)
@@ -3313,6 +3327,21 @@ class floating(inexact[_NBit1]):
33133327
__args: Union[L[0], Tuple[()], Tuple[L[0]]] = ...,
33143328
) -> float: ...
33153329
def tolist(self) -> float: ...
3330+
def is_integer(self: float64) -> bool: ...
3331+
def hex(self: float64) -> str: ...
3332+
@classmethod
3333+
def fromhex(cls: Type[float64], __string: str) -> float64: ...
3334+
def as_integer_ratio(self) -> Tuple[int, int]: ...
3335+
if sys.version_info >= (3, 9):
3336+
def __ceil__(self: float64) -> int: ...
3337+
def __floor__(self: float64) -> int: ...
3338+
def __trunc__(self: float64) -> int: ...
3339+
def __getnewargs__(self: float64) -> Tuple[float]: ...
3340+
def __getformat__(self: float64, __typestr: L["double", "float"]) -> str: ...
3341+
@overload
3342+
def __round__(self, ndigits: None = ...) -> int: ...
3343+
@overload
3344+
def __round__(self: _ScalarType, ndigits: SupportsIndex) -> _ScalarType: ...
33163345
__add__: _FloatOp[_NBit1]
33173346
__radd__: _FloatOp[_NBit1]
33183347
__sub__: _FloatOp[_NBit1]
@@ -3357,6 +3386,9 @@ class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):
33573386
@property
33583387
def imag(self) -> floating[_NBit2]: ... # type: ignore[override]
33593388
def __abs__(self) -> floating[_NBit1]: ... # type: ignore[override]
3389+
def __getnewargs__(self: complex128) -> Tuple[float, float]: ...
3390+
# NOTE: Deprecated
3391+
# def __round__(self, ndigits=...): ...
33603392
__add__: _ComplexOp[_NBit1]
33613393
__radd__: _ComplexOp[_NBit1]
33623394
__sub__: _ComplexOp[_NBit1]

0 commit comments

Comments
 (0)