Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 295e2d5

Browse filesBrowse files
authored
TYP: Type ma.max and ma.ptp (#28612)
* TYP: Type ma.max and ma.ptp * lint
1 parent a9a9bf8 commit 295e2d5
Copy full SHA for 295e2d5

File tree

Expand file treeCollapse file tree

3 files changed

+99
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+99
-6
lines changed

‎numpy/ma/core.pyi

Copy file name to clipboardExpand all lines: numpy/ma/core.pyi
+67-2Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,73 @@ def min(
603603
keepdims: bool | _NoValueType = ...,
604604
) -> _ArrayType: ...
605605

606-
def max(obj, axis=..., out=..., fill_value=..., keepdims=...): ...
607-
def ptp(obj, axis=..., out=..., fill_value=..., keepdims=...): ...
606+
@overload
607+
def max(
608+
obj: _ArrayLike[_SCT],
609+
axis: None = None,
610+
out: None = None,
611+
fill_value: _ScalarLike_co | None = None,
612+
keepdims: Literal[False] | _NoValueType = ...,
613+
) -> _SCT: ...
614+
@overload
615+
def max(
616+
obj: ArrayLike,
617+
axis: _ShapeLike | None = None,
618+
out: None = None,
619+
fill_value: _ScalarLike_co | None = None,
620+
keepdims: bool | _NoValueType = ...
621+
) -> Any: ...
622+
@overload
623+
def max(
624+
obj: ArrayLike,
625+
axis: None,
626+
out: _ArrayType,
627+
fill_value: _ScalarLike_co | None = None,
628+
keepdims: bool | _NoValueType = ...,
629+
) -> _ArrayType: ...
630+
@overload
631+
def max(
632+
obj: ArrayLike,
633+
axis: _ShapeLike | None = None,
634+
*,
635+
out: _ArrayType,
636+
fill_value: _ScalarLike_co | None = None,
637+
keepdims: bool | _NoValueType = ...,
638+
) -> _ArrayType: ...
639+
640+
@overload
641+
def ptp(
642+
obj: _ArrayLike[_SCT],
643+
axis: None = None,
644+
out: None = None,
645+
fill_value: _ScalarLike_co | None = None,
646+
keepdims: Literal[False] | _NoValueType = ...,
647+
) -> _SCT: ...
648+
@overload
649+
def ptp(
650+
obj: ArrayLike,
651+
axis: _ShapeLike | None = None,
652+
out: None = None,
653+
fill_value: _ScalarLike_co | None = None,
654+
keepdims: bool | _NoValueType = ...
655+
) -> Any: ...
656+
@overload
657+
def ptp(
658+
obj: ArrayLike,
659+
axis: None,
660+
out: _ArrayType,
661+
fill_value: _ScalarLike_co | None = None,
662+
keepdims: bool | _NoValueType = ...,
663+
) -> _ArrayType: ...
664+
@overload
665+
def ptp(
666+
obj: ArrayLike,
667+
axis: _ShapeLike | None = None,
668+
*,
669+
out: _ArrayType,
670+
fill_value: _ScalarLike_co | None = None,
671+
keepdims: bool | _NoValueType = ...,
672+
) -> _ArrayType: ...
608673

609674
class _frommethod:
610675
__name__: Any

‎numpy/typing/tests/data/fail/ma.pyi

Copy file name to clipboardExpand all lines: numpy/typing/tests/data/fail/ma.pyi
+14-4Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
88
m.shape = (3, 1) # E: Incompatible types in assignment
99
m.dtype = np.bool # E: Incompatible types in assignment
1010

11-
np.amin(m, axis=1.0) # E: No overload variant
12-
np.amin(m, keepdims=1.0) # E: No overload variant
13-
np.amin(m, out=1.0) # E: No overload variant
14-
np.amin(m, fill_value=lambda x: 27) # E: No overload variant
11+
np.ma.min(m, axis=1.0) # E: No overload variant
12+
np.ma.min(m, keepdims=1.0) # E: No overload variant
13+
np.ma.min(m, out=1.0) # E: No overload variant
14+
np.ma.min(m, fill_value=lambda x: 27) # E: No overload variant
15+
16+
np.ma.max(m, axis=1.0) # E: No overload variant
17+
np.ma.max(m, keepdims=1.0) # E: No overload variant
18+
np.ma.max(m, out=1.0) # E: No overload variant
19+
np.ma.max(m, fill_value=lambda x: 27) # E: No overload variant
20+
21+
np.ma.ptp(m, axis=1.0) # E: No overload variant
22+
np.ma.ptp(m, keepdims=1.0) # E: No overload variant
23+
np.ma.ptp(m, out=1.0) # E: No overload variant
24+
np.ma.ptp(m, fill_value=lambda x: 27) # E: No overload variant

‎numpy/typing/tests/data/reveal/ma.pyi

Copy file name to clipboardExpand all lines: numpy/typing/tests/data/reveal/ma.pyi
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@ assert_type(np.ma.min(MAR_b, keepdims=True), Any)
3131
assert_type(np.ma.min(MAR_f4, keepdims=True), Any)
3232
assert_type(np.ma.min(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
3333
assert_type(np.ma.min(MAR_f4, None, MAR_subclass), MaskedNDArraySubclass)
34+
35+
assert_type(np.ma.max(MAR_b), np.bool)
36+
assert_type(np.ma.max(MAR_f4), np.float32)
37+
assert_type(np.ma.max(MAR_b, axis=0), Any)
38+
assert_type(np.ma.max(MAR_f4, axis=0), Any)
39+
assert_type(np.ma.max(MAR_b, keepdims=True), Any)
40+
assert_type(np.ma.max(MAR_f4, keepdims=True), Any)
41+
assert_type(np.ma.max(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
42+
assert_type(np.ma.max(MAR_f4, None, MAR_subclass), MaskedNDArraySubclass)
43+
44+
assert_type(np.ma.ptp(MAR_b), np.bool)
45+
assert_type(np.ma.ptp(MAR_f4), np.float32)
46+
assert_type(np.ma.ptp(MAR_b, axis=0), Any)
47+
assert_type(np.ma.ptp(MAR_f4, axis=0), Any)
48+
assert_type(np.ma.ptp(MAR_b, keepdims=True), Any)
49+
assert_type(np.ma.ptp(MAR_f4, keepdims=True), Any)
50+
assert_type(np.ma.ptp(MAR_f4, out=MAR_subclass), MaskedNDArraySubclass)
51+
assert_type(np.ma.ptp(MAR_f4, None, MAR_subclass), MaskedNDArraySubclass)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.