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 75a2a3a

Browse filesBrowse files
authored
TYP: Type MaskedArray.partition and MaskedArray.argpartition (#28677)
1 parent 734e2cd commit 75a2a3a
Copy full SHA for 75a2a3a

File tree

Expand file treeCollapse file tree

3 files changed

+37
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+37
-2
lines changed

‎numpy/ma/core.pyi

Copy file name to clipboardExpand all lines: numpy/ma/core.pyi
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from typing_extensions import deprecated
99

1010
from numpy import (
1111
_OrderKACF,
12+
_PartitionKind,
1213
_SortKind,
1314
amax,
1415
amin,
@@ -26,6 +27,7 @@ from numpy._typing import (
2627
NDArray,
2728
_ArrayLike,
2829
_DTypeLikeBool,
30+
_ArrayLikeInt,
2931
_ScalarLike_co,
3032
_Shape,
3133
_ShapeLike,
@@ -665,8 +667,20 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
665667
) -> _ArrayT: ...
666668

667669
#
668-
def partition(self, *args, **kwargs): ...
669-
def argpartition(self, *args, **kwargs): ...
670+
def partition(
671+
self,
672+
kth: _ArrayLikeInt,
673+
axis: SupportsIndex = -1,
674+
kind: _PartitionKind = "introselect",
675+
order: str | Sequence[str] | None = None
676+
) -> None: ...
677+
def argpartition(
678+
self,
679+
kth: _ArrayLikeInt,
680+
axis: SupportsIndex = -1,
681+
kind: _PartitionKind = "introselect",
682+
order: str | Sequence[str] | None = None
683+
) -> _MaskedArray[intp]: ...
670684
def take(self, indices, axis=..., out=..., mode=...): ...
671685

672686
copy: Any

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

Copy file name to clipboardExpand all lines: numpy/typing/tests/data/fail/ma.pyi
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ from typing import Any
22

33
import numpy as np
44
import numpy.ma
5+
import numpy.typing as npt
56

67
m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
78

9+
AR_b: npt.NDArray[np.bool]
10+
811
m.shape = (3, 1) # E: Incompatible types in assignment
912
m.dtype = np.bool # E: Incompatible types in assignment
1013

@@ -68,3 +71,15 @@ m.sort(endwith='cabbage') # E: No overload variant
6871
m.sort(fill_value=lambda: 'cabbage') # E: No overload variant
6972
m.sort(stable='cabbage') # E: No overload variant
7073
m.sort(stable=True) # E: No overload variant
74+
75+
m.partition(['cabbage']) # E: No overload variant
76+
m.partition(axis=(0,1)) # E: No overload variant
77+
m.partition(kind='cabbage') # E: No overload variant
78+
m.partition(order=lambda: 'cabbage') # E: No overload variant
79+
m.partition(AR_b) # E: No overload variant
80+
81+
m.argpartition(['cabbage']) # E: No overload variant
82+
m.argpartition(axis=(0,1)) # E: No overload variant
83+
m.argpartition(kind='cabbage') # E: No overload variant
84+
m.argpartition(order=lambda: 'cabbage') # E: No overload variant
85+
m.argpartition(AR_b) # 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
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ assert_type(np.ma.sort(MAR_f4), MaskedNDArray[np.float32])
128128
assert_type(np.ma.sort(MAR_subclass), MaskedNDArraySubclass)
129129
assert_type(np.ma.sort([[0, 1], [2, 3]]), NDArray[Any])
130130
assert_type(np.ma.sort(AR_f4), NDArray[np.float32])
131+
132+
assert_type(MAR_f4.partition(1), None)
133+
assert_type(MAR_f4.partition(1, axis=0, kind='introselect', order='K'), None)
134+
135+
assert_type(MAR_f4.argpartition(1), MaskedNDArray[np.intp])
136+
assert_type(MAR_1d.argpartition(1, axis=0, kind='introselect', order='K'), MaskedNDArray[np.intp])

0 commit comments

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