From f536d803470f230b6ce2d762db1e10d97918fd8b Mon Sep 17 00:00:00 2001 From: GUAN MING Date: Sat, 22 Mar 2025 19:43:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`signbit`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/umath.pyi | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/numpy-stubs/_core/umath.pyi b/src/numpy-stubs/_core/umath.pyi index 21b2121c..7a9227cf 100644 --- a/src/numpy-stubs/_core/umath.pyi +++ b/src/numpy-stubs/_core/umath.pyi @@ -446,6 +446,39 @@ class _Call11Isnat(Protocol): **kwds: Unpack[_Kwargs2], ) -> NDArray[np.bool]: ... +@type_check_only +class _Call11Signbit(Protocol): + @overload # (scalar) -> bool + def __call__( + self, + x: _FloatLike_co, + /, + out: None = None, + *, + dtype: _DTypeLikeBool | None = None, + **kwds: Unpack[_Kwargs2], + ) -> np.bool: ... + @overload # (array-like, out: T) -> T + def __call__( + self, + x: _ArrayLikeFloat_co, + /, + out: _Out1[_ArrayT], + *, + dtype: _DTypeLikeBool | None = None, + **kwds: Unpack[_Kwargs2], + ) -> _ArrayT: ... + @overload # (array) -> Array[bool] + def __call__( + self, + x: NDArray[np.floating] | _NestedSequence[np.floating], + /, + out: _Out1[NDArray[np.floating]] | None = None, + *, + dtype: _DTypeLikeBool | None = None, + **kwds: Unpack[_Kwargs2], + ) -> NDArray[np.bool]: ... + @type_check_only class _Call11Logical(Protocol): @overload @@ -1384,7 +1417,9 @@ _ufunc_2_2 = TypeAliasType( isnat: Final[_ufunc_1_1[_Call11Isnat]] = ... # {[f]} -> ? -signbit: Final[_ufunc_1_1] = ... +signbit: Final[_ufunc_1_1[_Call11Signbit]] = ... + +# {?[uifc]Mm} -> ? isfinite: Final[_ufunc_1_1[_Call11Bool]] = ... isinf: Final[_ufunc_1_1[_Call11Bool]] = ... From e75dbcb82d86a409b43c6904a9053d21dc627a20 Mon Sep 17 00:00:00 2001 From: GUAN MING Date: Sat, 22 Mar 2025 19:43:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20add=20`signbit`=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/static/accept/ufuncs.pyi | 4 ++++ test/static/reject/ufuncs.pyi | 3 +++ 2 files changed, 7 insertions(+) diff --git a/test/static/accept/ufuncs.pyi b/test/static/accept/ufuncs.pyi index 74435508..22908343 100644 --- a/test/static/accept/ufuncs.pyi +++ b/test/static/accept/ufuncs.pyi @@ -96,3 +96,7 @@ assert_type(np.spacing(f8), np.float64) assert_type(np.spacing(AR_f8), npt.NDArray[np.float64]) assert_type(np.spacing(AR_f4), npt.NDArray[np.floating]) assert_type(np.spacing(AR_f8, out=AR_f8), npt.NDArray[np.float64]) + +assert_type(np.signbit(f8), np.bool_) +assert_type(np.signbit(AR_f8), npt.NDArray[np.bool_]) +assert_type(np.signbit(AR_f8, out=AR_bool), npt.NDArray[np.bool_]) diff --git a/test/static/reject/ufuncs.pyi b/test/static/reject/ufuncs.pyi index 35e69f0f..59adb9bd 100644 --- a/test/static/reject/ufuncs.pyi +++ b/test/static/reject/ufuncs.pyi @@ -63,3 +63,6 @@ np.logical_xor(dt64, dt64, dtype=np.datetime64) # type: ignore[arg-type] # pyr np.spacing(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] np.spacing(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] + +np.signbit(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.signbit(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]