Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c200e8c

Browse files
authored
Merge pull request #28758 from charris/backport-28747
TYP: some ``[arg]partition`` fixes
2 parents 90fdcf9 + cbafc53 commit c200e8c

File tree

2 files changed

+60
-24
lines changed

2 files changed

+60
-24
lines changed

numpy/__init__.pyi

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,14 +2293,47 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
22932293
where: _ArrayLikeBool_co = True,
22942294
) -> _ArrayT: ...
22952295

2296+
#
2297+
@overload
2298+
def partition(
2299+
self,
2300+
/,
2301+
kth: _ArrayLikeInt,
2302+
axis: SupportsIndex = -1,
2303+
kind: _PartitionKind = "introselect",
2304+
order: None = None,
2305+
) -> None: ...
2306+
@overload
2307+
def partition(
2308+
self: NDArray[void],
2309+
/,
2310+
kth: _ArrayLikeInt,
2311+
axis: SupportsIndex = -1,
2312+
kind: _PartitionKind = "introselect",
2313+
order: str | Sequence[str] | None = None,
2314+
) -> None: ...
2315+
2316+
#
2317+
@overload
22962318
def argpartition(
22972319
self,
2298-
kth: _ArrayLikeInt_co,
2299-
axis: None | SupportsIndex = ...,
2300-
kind: _PartitionKind = ...,
2301-
order: None | str | Sequence[str] = ...,
2320+
/,
2321+
kth: _ArrayLikeInt,
2322+
axis: SupportsIndex | None = -1,
2323+
kind: _PartitionKind = "introselect",
2324+
order: None = None,
2325+
) -> NDArray[intp]: ...
2326+
@overload
2327+
def argpartition(
2328+
self: NDArray[void],
2329+
/,
2330+
kth: _ArrayLikeInt,
2331+
axis: SupportsIndex | None = -1,
2332+
kind: _PartitionKind = "introselect",
2333+
order: str | Sequence[str] | None = None,
23022334
) -> NDArray[intp]: ...
23032335

2336+
#
23042337
def diagonal(
23052338
self,
23062339
offset: SupportsIndex = ...,
@@ -2320,14 +2353,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
23202353
# `nonzero()` is deprecated for 0d arrays/generics
23212354
def nonzero(self) -> tuple[NDArray[intp], ...]: ...
23222355

2323-
def partition(
2324-
self,
2325-
kth: _ArrayLikeInt_co,
2326-
axis: SupportsIndex = ...,
2327-
kind: _PartitionKind = ...,
2328-
order: None | str | Sequence[str] = ...,
2329-
) -> None: ...
2330-
23312356
# `put` is technically available to `generic`,
23322357
# but is pointless as `generic`s are immutable
23332358
def put(self, /, indices: _ArrayLikeInt_co, values: ArrayLike, mode: _ModeKind = "raise") -> None: ...

numpy/_core/fromnumeric.pyi

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ from numpy._typing import (
4747
_ShapeLike,
4848
_ArrayLikeBool_co,
4949
_ArrayLikeUInt_co,
50+
_ArrayLikeInt,
5051
_ArrayLikeInt_co,
5152
_ArrayLikeFloat_co,
5253
_ArrayLikeComplex_co,
5354
_ArrayLikeObject_co,
54-
_ArrayLikeTD64_co,
5555
_IntLike_co,
5656
_BoolLike_co,
5757
_ComplexLike_co,
@@ -322,31 +322,42 @@ def matrix_transpose(x: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
322322
@overload
323323
def matrix_transpose(x: ArrayLike, /) -> NDArray[Any]: ...
324324

325+
#
325326
@overload
326327
def partition(
327328
a: _ArrayLike[_SCT],
328-
kth: _ArrayLikeInt_co,
329-
axis: SupportsIndex | None = ...,
330-
kind: _PartitionKind = ...,
331-
order: str | Sequence[str] | None = ...,
329+
kth: _ArrayLikeInt,
330+
axis: SupportsIndex | None = -1,
331+
kind: _PartitionKind = "introselect",
332+
order: None = None,
332333
) -> NDArray[_SCT]: ...
333334
@overload
335+
def partition(
336+
a: _ArrayLike[np.void],
337+
kth: _ArrayLikeInt,
338+
axis: SupportsIndex | None = -1,
339+
kind: _PartitionKind = "introselect",
340+
order: str | Sequence[str] | None = None,
341+
) -> NDArray[np.void]: ...
342+
@overload
334343
def partition(
335344
a: ArrayLike,
336-
kth: _ArrayLikeInt_co,
337-
axis: SupportsIndex | None = ...,
338-
kind: _PartitionKind = ...,
339-
order: str | Sequence[str] | None = ...,
345+
kth: _ArrayLikeInt,
346+
axis: SupportsIndex | None = -1,
347+
kind: _PartitionKind = "introselect",
348+
order: str | Sequence[str] | None = None,
340349
) -> NDArray[Any]: ...
341350

351+
#
342352
def argpartition(
343353
a: ArrayLike,
344-
kth: _ArrayLikeInt_co,
354+
kth: _ArrayLikeInt,
345355
axis: SupportsIndex | None = -1,
346-
kind: _PartitionKind = ...,
347-
order: str | Sequence[str] | None = ...,
356+
kind: _PartitionKind = "introselect",
357+
order: str | Sequence[str] | None = None,
348358
) -> NDArray[intp]: ...
349359

360+
#
350361
@overload
351362
def sort(
352363
a: _ArrayLike[_SCT],

0 commit comments

Comments
 (0)