Skip to content

Commit adab6c2

Browse files
guan404mingMarcoGorellijorenham
committed
🚚 port numpy.ma.min
Co-Authored-By: Marco Edward Gorelli <[email protected]> Co-Authored-By: Joren Hammudoglu <[email protected]>
1 parent 79b5462 commit adab6c2

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

‎src/numpy-stubs/@test/static/accept/ma.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Any, TypeAlias, TypeVar
12
from typing_extensions import assert_type
23

34
import numpy as np
5+
from numpy._typing import _Shape
46

57
m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
68

@@ -10,3 +12,14 @@ assert_type(m.dtype, np.dtype[np.float64])
1012

1113
assert_type(int(m), int)
1214
assert_type(float(m), float)
15+
16+
_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True)
17+
MaskedNDArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT_co]]
18+
19+
class MaskedNDArraySubclass(MaskedNDArray[np.complex128]): ...
20+
21+
MAR_b: MaskedNDArray[np.bool]
22+
MAR_f4: MaskedNDArray[np.float32]
23+
MAR_i8: MaskedNDArray[np.int64]
24+
MAR_subclass: MaskedNDArraySubclass
25+
MAR_1d: np.ma.MaskedArray[tuple[int], np.dtype[Any]]

‎src/numpy-stubs/@test/static/reject/ma.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
44

55
m.shape = (3, 1) # type: ignore[assignment]
66
m.dtype = np.bool # type: ignore[assignment] # pyright: ignore[reportAttributeAccessIssue]
7+
8+
np.amin(m, axis=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue]
9+
np.amin(m, keepdims=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue]
10+
np.amin(m, out=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue]
11+
np.amin(m, fill_value=lambda x: 27) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportUnknownLambdaType]

‎src/numpy-stubs/ma/core.pyi

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ from typing_extensions import Never, Self, TypeVar, deprecated, overload, overri
55
import numpy as np
66
from _numtype import Array, ToGeneric_0d, ToGeneric_1nd, ToGeneric_nd
77
from numpy import _OrderACF, _OrderKACF, amax, amin, bool_, expand_dims # noqa: ICN003
8-
from numpy._typing import _BoolCodes
8+
from numpy._globals import _NoValueType
9+
from numpy._typing import ArrayLike, _ArrayLike, _BoolCodes, _ScalarLike_co, _ShapeLike
910

1011
__all__ = [
1112
"MAError",
@@ -188,7 +189,9 @@ __all__ = [
188189
"zeros_like",
189190
]
190191

192+
_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any])
191193
_UFuncT_co = TypeVar("_UFuncT_co", bound=np.ufunc, default=np.ufunc, covariant=True)
194+
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
192195
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
193196
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=tuple[int, ...], covariant=True)
194197
_DTypeT = TypeVar("_DTypeT", bound=np.dtype)
@@ -818,13 +821,41 @@ def array(
818821
) -> Incomplete: ...
819822

820823
#
824+
@overload
821825
def min(
822-
obj: Incomplete,
823-
axis: Incomplete = ...,
824-
out: Incomplete = ...,
825-
fill_value: Incomplete = ...,
826-
keepdims: Incomplete = ...,
827-
) -> Incomplete: ...
826+
obj: _ArrayLike[_ScalarT],
827+
axis: None = None,
828+
out: None = None,
829+
fill_value: _ScalarLike_co | None = None,
830+
keepdims: L[False] | _NoValueType = ...,
831+
) -> _ScalarT: ...
832+
@overload
833+
def min(
834+
obj: ArrayLike,
835+
axis: _ShapeLike | None = None,
836+
out: None = None,
837+
fill_value: _ScalarLike_co | None = None,
838+
keepdims: bool | _NoValueType = ...,
839+
) -> Any: ...
840+
@overload
841+
def min(
842+
obj: ArrayLike,
843+
axis: None,
844+
out: _ArrayT,
845+
fill_value: _ScalarLike_co | None = None,
846+
keepdims: bool | _NoValueType = ...,
847+
) -> _ArrayT: ...
848+
@overload
849+
def min(
850+
obj: ArrayLike,
851+
axis: _ShapeLike | None = None,
852+
*,
853+
out: _ArrayT,
854+
fill_value: _ScalarLike_co | None = None,
855+
keepdims: bool | _NoValueType = ...,
856+
) -> _ArrayT: ...
857+
858+
#
828859
def max(
829860
obj: Incomplete,
830861
axis: Incomplete = ...,

0 commit comments

Comments
 (0)