10000 TYP: Type ``ma.max`` and ``ma.ptp`` by MarcoGorelli · Pull Request #28612 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Type ma.max and ma.ptp #28612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2025
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
69 changes: 67 additions & 2 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,73 @@ def min(
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

def max(obj, axis=..., out=..., fill_value=..., keepdims=...): ...
def ptp(obj, axis=..., out=..., fill_value=..., keepdims=...): ...
@overload
def max(
obj: _ArrayLike[_SCT],
axis: None = None,
out: None = None,
fill_value: _ScalarLike_co | None = None,
keepdims: Literal[False] | _NoValueType = ...,
) -> _SCT: ...
@overload
def max(
obj: ArrayLike,
axis: _ShapeLike | None = None,
out: None = None,
fill_value: _ScalarLike_co | None = None,
keepdims: bool | _NoValueType = ...
) -> Any: ...
@overload
def max(
obj: ArrayLike,
axis: None,
out: _ArrayType,
fill_value: _ScalarLike_co | None = None,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...
@overload
def max(
obj: ArrayLike,
axis: _ShapeLike | None = None,
*,
out: _ArrayType,
fill_value: _ScalarLike_co | None = None,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

@overload
def ptp(
obj: _ArrayLike[_SCT],
axis: None = None,
out: None = None,
fill_value: _ScalarLike_co | None = None,
keepdims: Literal[False] | _NoValueType = ...,
) -> _SCT: ...
@overload
def ptp(
obj: ArrayLike,
axis: _ShapeLike | None = None,
out: None = None,
fill_value: _ScalarLike_co | None = None,
keepdims: bool | _NoValueType = ...
) -> Any: ...
@overload
def ptp(
obj: ArrayLike,
axis: None,
out: _ArrayType,
fill_value: _ScalarLike_co | None = None,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...
@overload
def ptp(
obj: ArrayLike,
axis: _ShapeLike | None = None,
*,
out: _ArrayType,
fill_value: _ScalarLike_co | None = None,
keepdims: bool | _NoValueType = ...,
) -> _ArrayType: ...

class _frommethod:
__name__: Any
Expand Down
18 changes: 14 additions & 4 deletions numpy/typing/tests/data/fail/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
m.shape = (3, 1) # E: Incompatible types in assignment
m.dtype = np.bool # E: Incompatible types in assignment

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

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

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

assert_type(np.ma.max(MAR_b), np.bool)
assert_type(np.ma.max(MAR_f4), np.float32)
assert_type(np.ma.max(MAR_b, axis=0), Any)
assert_type(np.ma.max(MAR_f4, axis=0), Any)
assert_type(np.ma.max(MAR_b, keepdims=True), Any)
assert_type(np.ma.max(MAR_f4, keepdims=True), Any)
assert_type(np.ma.max(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
assert_type(np.ma.max(MAR_f4, None, MAR_subclass), MaskedNDArraySubclass)

assert_type(np.ma.ptp(MAR_b), np.bool)
assert_type(np.ma.ptp(MAR_f4), np.float32)
assert_type(np.ma.ptp(MAR_b, axis=0), Any)
assert_type(np.ma.ptp(MAR_f4, axis=0), Any)
assert_type(np.ma.ptp(MAR_b, keepdims=True), Any)
assert_type(np.ma.ptp(MAR_f4, keepdims=True), Any)
assert_type(np.ma.ptp(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
assert_type(np.ma.ptp(MAR_f4, None, MAR_subclass), MaskedNDArraySubclass)
Loading
0