Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/numpy-stubs/@test/static/accept/ma.pyi
Original file line number Diff line number Diff line change
@@ -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]]

Expand All @@ -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]]
5 changes: 5 additions & 0 deletions src/numpy-stubs/@test/static/reject/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
45 changes: 38 additions & 7 deletions src/numpy-stubs/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = ...,
Expand Down