🌐 AI搜索 & 代理 主页
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
157 changes: 153 additions & 4 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from _typeshed import Incomplete
from typing_extensions import deprecated

from numpy import (
intp,
_OrderKACF,
amax,
amin,
Expand Down Expand Up @@ -465,8 +466,84 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
def std(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
def round(self, decimals=..., out=...): ...
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
def argmin(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
def argmax(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...

# Keep in-sync with np.ma.argmin
@overload
def argmin( # type: ignore[override]
self,
axis: None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: Literal[False] | _NoValueType = ...,
) -> intp: ...
@overload
def argmin( # type: ignore[override]
self,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: bool | _NoValueType = ...,
) -> Any: ...
@overload
def argmin( # type: ignore[override]
self,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
*,
out: _ArrayType,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...
@overload
def argmin( # type: ignore[override]
self,
axis: SupportsIndex | None,
fill_value: _ScalarLike_co | None,
out: _ArrayType,
*,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

# Keep in-sync with np.ma.argmax
@overload
def argmax( # type: ignore[override]
self,
axis: None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: Literal[False] | _NoValueType = ...,
) -> intp: ...
@overload
def argmax( # type: ignore[override]
self,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: bool | _NoValueType = ...,
) -> Any: ...
@overload
def argmax( # type: ignore[override]
self,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
*,
out: _ArrayType,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...
@overload
def argmax( # type: ignore[override]
self,
axis: SupportsIndex | None,
fill_value: _ScalarLike_co | None,
out: _ArrayType,
*,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

#
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
@overload
def min( # type: ignore[override]
Expand Down Expand Up @@ -801,8 +878,80 @@ swapaxes: _frommethod
trace: _frommethod
var: _frommethod
count: _frommethod
argmin: _frommethod
argmax: _frommethod

@overload
def argmin(
self: ArrayLike,
axis: None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: Literal[False] | _NoValueType = ...,
) -> intp: ...
@overload
def argmin(
self: ArrayLike,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: bool | _NoValueType = ...,
) -> Any: ...
@overload
def argmin(
self: ArrayLike,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
*,
out: _ArrayType,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...
@overload
def argmin(
self: ArrayLike,
axis: SupportsIndex | None,
fill_value: _ScalarLike_co | None,
out: _ArrayType,
*,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

@overload
def argmax(
self: ArrayLike,
axis: None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: Literal[False] | _NoValueType = ...,
) -> intp: ...
@overload
def argmax(
self: ArrayLike,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
out: None = None,
*,
keepdims: bool | _NoValueType = ...,
) -> Any: ...
@overload
def argmax(
self: ArrayLike,
axis: SupportsIndex | None = None,
fill_value: _ScalarLike_co | None = None,
*,
out: _ArrayType,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...
@overload
def argmax(
self: ArrayLike,
axis: SupportsIndex | None,
fill_value: _ScalarLike_co | None,
out: _ArrayType,
*,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

minimum: _extrema_operation
maximum: _extrema_operation
Expand Down
22 changes: 22 additions & 0 deletions numpy/typing/tests/data/fail/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ m.ptp(axis=1.0) # E: No overload variant
m.ptp(keepdims=1.0) # E: No overload variant
m.ptp(out=1.0) # E: No overload variant
m.ptp(fill_value=lambda x: 27) # E: No overload variant

m.argmin(axis=1.0) # E: No overload variant
m.argmin(keepdims=1.0) # E: No overload variant
m.argmin(out=1.0) # E: No overload variant
m.argmin(fill_value=lambda x: 27) # E: No overload variant

np.ma.argmin(m, axis=1.0) # E: No overload variant
np.ma.argmin(m, axis=(1,)) # E: No overload variant
np.ma.argmin(m, keepdims=1.0) # E: No overload variant
np.ma.argmin(m, out=1.0) # E: No overload variant
np.ma.argmin(m, fill_value=lambda x: 27) # E: No overload variant

m.argmax(axis=1.0) # E: No overload variant
m.argmax(keepdims=1.0) # E: No overload variant
m.argmax(out=1.0) # E: No overload variant
m.argmax(fill_value=lambda x: 27) # E: No overload variant

np.ma.argmax(m, axis=1.0) # E: No overload variant
np.ma.argmax(m, axis=(0,)) # E: No overload variant
np.ma.argmax(m, keepdims=1.0) # E: No overload variant
np.ma.argmax(m, out=1.0) # E: No overload variant
np.ma.argmax(m, fill_value=lambda x: 27) # E: No overload variant
36 changes: 36 additions & 0 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,39 @@ assert_type(MAR_f4.ptp(keepdims=True), Any)
assert_type(MAR_f4.ptp(out=MAR_subclass), MaskedNDArraySubclass)
assert_type(MAR_f4.ptp(0, MAR_subclass), MaskedNDArraySubclass)
assert_type(MAR_f4.ptp(None, MAR_subclass), MaskedNDArraySubclass)

assert_type(MAR_b.argmin(), np.intp)
assert_type(MAR_f4.argmin(), np.intp)
assert_type(MAR_f4.argmax(fill_value=6.28318, keepdims=False), np.intp)
assert_type(MAR_b.argmin(axis=0), Any)
assert_type(MAR_f4.argmin(axis=0), Any)
assert_type(MAR_b.argmin(keepdims=True), Any)
assert_type(MAR_f4.argmin(out=MAR_subclass), MaskedNDArraySubclass)
assert_type(MAR_f4.argmin(None, None, out=MAR_subclass), MaskedNDArraySubclass)

assert_type(np.ma.argmin(MAR_b), np.intp)
assert_type(np.ma.argmin(MAR_f4), np.intp)
assert_type(np.ma.argmin(MAR_f4, fill_value=6.28318, keepdims=False), np.intp)
assert_type(np.ma.argmin(MAR_b, axis=0), Any)
assert_type(np.ma.argmin(MAR_f4, axis=0), Any)
assert_type(np.ma.argmin(MAR_b, keepdims=True), Any)
assert_type(np.ma.argmin(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
assert_type(np.ma.argmin(MAR_f4, None, None, out=MAR_subclass), MaskedNDArraySubclass)

assert_type(MAR_b.argmax(), np.intp)
assert_type(MAR_f4.argmax(), np.intp)
assert_type(MAR_f4.argmax(fill_value=6.28318, keepdims=False), np.intp)
assert_type(MAR_b.argmax(axis=0), Any)
assert_type(MAR_f4.argmax(axis=0), Any)
assert_type(MAR_b.argmax(keepdims=True), Any)
assert_type(MAR_f4.argmax(out=MAR_subclass), MaskedNDArraySubclass)
assert_type(MAR_f4.argmax(None, None, out=MAR_subclass), MaskedNDArraySubclass)

assert_type(np.ma.argmax(MAR_b), np.intp)
assert_type(np.ma.argmax(MAR_f4), np.intp)
assert_type(np.ma.argmax(MAR_f4, fill_value=6.28318, keepdims=False), np.intp)
assert_type(np.ma.argmax(MAR_b, axis=0), Any)
assert_type(np.ma.argmax(MAR_f4, axis=0), Any)
assert_type(np.ma.argmax(MAR_b, keepdims=True), Any)
assert_type(np.ma.argmax(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
assert_type(np.ma.argmax(MAR_f4, None, None, out=MAR_subclass), MaskedNDArraySubclass)
Loading