Skip to content

Commit d80837f

Browse files
guan404mingMarcoGorellijorenham
committed
🚚 port numpy.ma.min
Co-Authored-By: Marco Edward Gorelli <33491632+marcogorelli@users.noreply.github.com> Co-Authored-By: Joren Hammudoglu <jhammudoglu@gmail.com>
1 parent 79b5462 commit d80837f

File tree

4 files changed

+66
-19
lines changed

4 files changed

+66
-19
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+
_ScalarType_co = TypeVar("_ScalarType_co", bound=np.generic, covariant=True)
17+
MaskedNDArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarType_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: 36 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",
@@ -195,6 +196,8 @@ _DTypeT = TypeVar("_DTypeT", bound=np.dtype)
195196
_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, default=np.dtype, covariant=True)
196197

197198
_DTypeLikeBool: TypeAlias = type[bool | np.bool] | np.dtype[np.bool] | _BoolCodes
199+
_ArrayType = TypeVar("_ArrayType", bound=np.ndarray[Any, Any])
200+
_SCT = TypeVar("_SCT", bound=np.generic)
198201

199202
###
200203

@@ -818,13 +821,39 @@ 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[_SCT],
827+
axis: None = None,
828+
out: None = None,
829+
fill_value: _ScalarLike_co | None = None,
830+
keepdims: L[False] | _NoValueType = ...,
831+
) -> _SCT: ...
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: _ArrayType,
845+
fill_value: _ScalarLike_co | None = None,
846+
keepdims: bool | _NoValueType = ...,
847+
) -> _ArrayType: ...
848+
@overload
849+
def min(
850+
obj: ArrayLike,
851+
axis: _ShapeLike | None = None,
852+
*,
853+
out: _ArrayType,
854+
fill_value: _ScalarLike_co | None = None,
855+
keepdims: bool | _NoValueType = ...,
856+
) -> _ArrayType: ...
828857
def max(
829858
obj: Incomplete,
830859
axis: Incomplete = ...,

‎uv.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)