diff --git a/src/numpy-stubs/@test/static/accept/ma.pyi b/src/numpy-stubs/@test/static/accept/ma.pyi index edc8c10b..c794a281 100644 --- a/src/numpy-stubs/@test/static/accept/ma.pyi +++ b/src/numpy-stubs/@test/static/accept/ma.pyi @@ -1,6 +1,8 @@ +from typing import Any, TypeAlias, TypeVar from typing_extensions import assert_type import numpy as np +from numpy._typing import _Shape m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]] @@ -10,3 +12,14 @@ assert_type(m.dtype, np.dtype[np.float64]) assert_type(int(m), int) assert_type(float(m), float) + +_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True) +MaskedNDArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT_co]] + +class MaskedNDArraySubclass(MaskedNDArray[np.complex128]): ... + +MAR_b: MaskedNDArray[np.bool] +MAR_f4: MaskedNDArray[np.float32] +MAR_i8: MaskedNDArray[np.int64] +MAR_subclass: MaskedNDArraySubclass +MAR_1d: np.ma.MaskedArray[tuple[int], np.dtype[Any]] diff --git a/src/numpy-stubs/@test/static/reject/ma.pyi b/src/numpy-stubs/@test/static/reject/ma.pyi index aef6d21b..8463f8d5 100644 --- a/src/numpy-stubs/@test/static/reject/ma.pyi +++ b/src/numpy-stubs/@test/static/reject/ma.pyi @@ -4,3 +4,8 @@ m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]] m.shape = (3, 1) # type: ignore[assignment] m.dtype = np.bool # type: ignore[assignment] # pyright: ignore[reportAttributeAccessIssue] + +np.amin(m, axis=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] +np.amin(m, keepdims=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] +np.amin(m, out=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] +np.amin(m, fill_value=lambda x: 27) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportUnknownLambdaType] diff --git a/src/numpy-stubs/ma/core.pyi b/src/numpy-stubs/ma/core.pyi index 870d0d88..2037feaa 100644 --- a/src/numpy-stubs/ma/core.pyi +++ b/src/numpy-stubs/ma/core.pyi @@ -5,7 +5,8 @@ from typing_extensions import Never, Self, TypeVar, deprecated, overload, overri import numpy as np from _numtype import Array, ToGeneric_0d, ToGeneric_1nd, ToGeneric_nd from numpy import _OrderACF, _OrderKACF, amax, amin, bool_, expand_dims # noqa: ICN003 -from numpy._typing import _BoolCodes +from numpy._globals import _NoValueType +from numpy._typing import ArrayLike, _ArrayLike, _BoolCodes, _ScalarLike_co, _ShapeLike __all__ = [ "MAError", @@ -188,7 +189,9 @@ __all__ = [ "zeros_like", ] +_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any]) _UFuncT_co = TypeVar("_UFuncT_co", bound=np.ufunc, default=np.ufunc, covariant=True) +_ScalarT = TypeVar("_ScalarT", bound=np.generic) _ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=tuple[int, ...], covariant=True) _DTypeT = TypeVar("_DTypeT", bound=np.dtype) @@ -818,13 +821,41 @@ def array( ) -> Incomplete: ... # +@overload def min( - obj: Incomplete, - axis: Incomplete = ..., - out: Incomplete = ..., - fill_value: Incomplete = ..., - keepdims: Incomplete = ..., -) -> Incomplete: ... + obj: _ArrayLike[_ScalarT], + axis: None = None, + out: None = None, + fill_value: _ScalarLike_co | None = None, + keepdims: L[False] | _NoValueType = ..., +) -> _ScalarT: ... +@overload +def min( + obj: ArrayLike, + axis: _ShapeLike | None = None, + out: None = None, + fill_value: _ScalarLike_co | None = None, + keepdims: bool | _NoValueType = ..., +) -> Any: ... +@overload +def min( + obj: ArrayLike, + axis: None, + out: _ArrayT, + fill_value: _ScalarLike_co | None = None, + keepdims: bool | _NoValueType = ..., +) -> _ArrayT: ... +@overload +def min( + obj: ArrayLike, + axis: _ShapeLike | None = None, + *, + out: _ArrayT, + fill_value: _ScalarLike_co | None = None, + keepdims: bool | _NoValueType = ..., +) -> _ArrayT: ... + +# def max( obj: Incomplete, axis: Incomplete = ...,