Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0a0d38b

Browse files
committed
TYP: np.argmin changes
1 parent00f2733 commit0a0d38b

File tree

2 files changed

+49
-38
lines changed

2 files changed

+49
-38
lines changed

‎numpy/_core/fromnumeric.pyi

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ _NumberOrObjectT = TypeVar("_NumberOrObjectT", bound=np.number | np.object_)
111111
_ArrayT=TypeVar("_ArrayT",bound=np.ndarray[Any,Any])
112112
_ShapeT=TypeVar("_ShapeT",bound=tuple[int, ...])
113113
_ShapeT_co=TypeVar("_ShapeT_co",bound=tuple[int, ...],covariant=True)
114+
_IndexArray=NDArray[np.signedinteger]|NDArray[np.unsignedinteger]|NDArray[np.bool_]# type alias for argmin / argmax
115+
_OutT=TypeVar("_OutT",bound=_IndexArray)# Type variable, must be assignable to _IndexArray
114116

115117
@type_check_only
116118
class_SupportsShape(Protocol[_ShapeT_co]):
@@ -401,35 +403,19 @@ def argsort(
401403
@overload
402404
defargmax(
403405
a:ArrayLike,
404-
axis:None= ...,
405-
out:None= ...,
406-
*,
407-
keepdims:Literal[False]= ...,
408-
)->intp: ...
409-
@overload
410-
defargmax(
411-
a:ArrayLike,
412-
axis:SupportsIndex|None= ...,
413-
out:None= ...,
406+
axis:int|None= ...,
414407
*,
415-
keepdims:bool= ...,
416-
)->Any: ...
417-
@overload
418-
defargmax(
419-
a:ArrayLike,
420-
axis:SupportsIndex|None,
421-
out:_ArrayT,
422-
*,
423-
keepdims:bool= ...,
424-
)->_ArrayT: ...
408+
keepdims:bool= ...
409+
)->np.integer: ...
410+
425411
@overload
426412
defargmax(
427413
a:ArrayLike,
428-
axis:SupportsIndex|None= ...,
414+
axis:int|None= ...,
429415
*,
430-
out:_ArrayT,
431-
keepdims:bool= ...,
432-
)->_ArrayT: ...
416+
out:_OutT,
417+
keepdims:bool= ...
418+
)->_OutT: ...
433419

434420
@overload
435421
defargmin(
@@ -439,14 +425,14 @@ def argmin(
439425
*,
440426
keepdims:Literal[False]= ...,
441427
)->intp: ...
442-
@overload
443-
defargmin(
444-
a:ArrayLike,
445-
axis:SupportsIndex|None= ...,
446-
out:None= ...,
447-
*,
448-
keepdims:bool= ...,
449-
)->Any: ...
428+
#@overload
429+
#def argmin(
430+
# a: ArrayLike,
431+
# axis: SupportsIndex | None = ...,
432+
# out: None = ...,
433+
# *,
434+
# keepdims: bool = ...,
435+
#) -> Any: ...
450436
@overload
451437
defargmin(
452438
a:ArrayLike,
@@ -463,15 +449,24 @@ def argmin(
463449
out:_ArrayT,
464450
keepdims:bool= ...,
465451
)->_ArrayT: ...
466-
467452
@overload
468-
defsearchsorted(
453+
defargmin(
469454
a:ArrayLike,
470-
v:_ScalarLike_co,
471-
side:_SortSide= ...,
472-
sorter:_ArrayLikeInt_co|None= ...,# 1D int array
473-
)->intp: ...
455+
axis:int|None= ...,
456+
*,
457+
keepdims:bool= ...
458+
)->np.integer: ...
459+
474460
@overload
461+
defargmin(
462+
a:ArrayLike,
463+
axis:int|None= ...,
464+
*,
465+
out:_OutT,
466+
keepdims:bool= ...
467+
)->_OutT: ...
468+
469+
overload
475470
defsearchsorted(
476471
a:ArrayLike,
477472
v:ArrayLike,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
importnumpyasnp
2+
fromnumpy.typingimportNDArray
3+
4+
arr=np.array([1,2,3])
5+
6+
out_int:NDArray[np.int64]=np.empty(())
7+
_=np.argmin(arr,out=out_int)# expected to pass
8+
_=np.argmax(arr,out=out_int)# expected to pass
9+
10+
out_bool:NDArray[np.bool_]=np.empty(())
11+
_=np.argmin(arr,out=out_bool)# expected to pass
12+
_=np.argmax(arr,out=out_bool)# expected to pass
13+
14+
out_bad:NDArray[np.float64]=np.empty(())
15+
_=np.argmin(arr,out=out_bad)# should fail static typing
16+
_=np.argmax(arr,out=out_bad)# should fail static typing

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp