Skip to content

Commit 2f782a2

Browse files
authored
Merge pull request numpy#19540 from BvB93/getlimits
MAINT: Update the `np.finfo` annotations
2 parents b908da6 + 34a9039 commit 2f782a2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

numpy/__init__.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3828,7 +3828,11 @@ class finfo(Generic[_FloatType]):
38283828
nmant: int
38293829
precision: int
38303830
resolution: _FloatType
3831-
tiny: _FloatType
3831+
smallest_subnormal: _FloatType
3832+
@property
3833+
def smallest_normal(self) -> _FloatType: ...
3834+
@property
3835+
def tiny(self) -> _FloatType: ...
38323836

38333837
# NOTE: Not technically a property, but this is the only way we can
38343838
# access the precision of the underlying float

numpy/core/getlimits.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class MachArLike(Generic[_NBit]):
2323
huge: floating[Any],
2424
tiny: floating[Any],
2525
ibeta: int,
26+
smallest_subnormal: None | floating[Any] = ...,
2627
# Expand `**kwargs` into keyword-only arguments
2728
machep: int,
2829
negep: int,
@@ -33,6 +34,8 @@ class MachArLike(Generic[_NBit]):
3334
irnd: int,
3435
ngrd: int,
3536
) -> None: ...
37+
@property
38+
def smallest_subnormal(self) -> NDArray[floating[_NBit]]: ...
3639
eps: NDArray[floating[_NBit]]
3740
epsilon: NDArray[floating[_NBit]]
3841
epsneg: NDArray[floating[_NBit]]
@@ -48,6 +51,7 @@ class MachArLike(Generic[_NBit]):
4851
ngrd: int
4952
precision: int
5053
resolution: NDArray[floating[_NBit]]
54+
smallest_normal: NDArray[floating[_NBit]]
5155
tiny: NDArray[floating[_NBit]]
5256
title: str
5357
xmax: NDArray[floating[_NBit]]

numpy/typing/tests/data/reveal/getlimits.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
reveal_type(finfo_f8.precision) # E: int
3535
reveal_type(finfo_f8.resolution) # E: {float64}
3636
reveal_type(finfo_f8.tiny) # E: {float64}
37+
reveal_type(finfo_f8.smallest_normal) # E: {float64}
38+
reveal_type(finfo_f8.smallest_subnormal) # E: {float64}
3739
reveal_type(finfo_f8.machar) # E: MachArLike[numpy.typing._64Bit]
3840

3941
reveal_type(np.iinfo(i)) # E: iinfo[{int_}]
@@ -56,6 +58,8 @@
5658
reveal_type(machar_f4.tiny) # E: numpy.ndarray[Any, numpy.dtype[{float32}]]
5759
reveal_type(machar_f4.xmax) # E: numpy.ndarray[Any, numpy.dtype[{float32}]]
5860
reveal_type(machar_f4.xmin) # E: numpy.ndarray[Any, numpy.dtype[{float32}]]
61+
reveal_type(machar_f4.smallest_subnormal) # E: numpy.ndarray[Any, numpy.dtype[{float32}]]
62+
reveal_type(machar_f4.smallest_normal) # E: numpy.ndarray[Any, numpy.dtype[{float32}]]
5963
reveal_type(machar_f4.iexp) # E: int
6064
reveal_type(machar_f4.irnd) # E: int
6165
reveal_type(machar_f4.it) # E: int

0 commit comments

Comments
 (0)