Skip to content

Commit e402559

Browse files
authored
🏷️ ufunc annotations for signbit (#372)
* 🏷️ stub `signbit` * ✅ add `signbit` test
1 parent 14826bb commit e402559

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/numpy-stubs/_core/umath.pyi

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,39 @@ class _Call11Isnat(Protocol):
446446
**kwds: Unpack[_Kwargs2],
447447
) -> NDArray[np.bool]: ...
448448

449+
@type_check_only
450+
class _Call11Signbit(Protocol):
451+
@overload # (scalar) -> bool
452+
def __call__(
453+
self,
454+
x: _FloatLike_co,
455+
/,
456+
out: None = None,
457+
*,
458+
dtype: _DTypeLikeBool | None = None,
459+
**kwds: Unpack[_Kwargs2],
460+
) -> np.bool: ...
461+
@overload # (array-like, out: T) -> T
462+
def __call__(
463+
self,
464+
x: _ArrayLikeFloat_co,
465+
/,
466+
out: _Out1[_ArrayT],
467+
*,
468+
dtype: _DTypeLikeBool | None = None,
469+
**kwds: Unpack[_Kwargs2],
470+
) -> _ArrayT: ...
471+
@overload # (array) -> Array[bool]
472+
def __call__(
473+
self,
474+
x: NDArray[np.floating] | _NestedSequence[np.floating],
475+
/,
476+
out: _Out1[NDArray[np.floating]] | None = None,
477+
*,
478+
dtype: _DTypeLikeBool | None = None,
479+
**kwds: Unpack[_Kwargs2],
480+
) -> NDArray[np.bool]: ...
481+
449482
@type_check_only
450483
class _Call11Logical(Protocol):
451484
@overload
@@ -1384,7 +1417,9 @@ _ufunc_2_2 = TypeAliasType(
13841417
isnat: Final[_ufunc_1_1[_Call11Isnat]] = ...
13851418

13861419
# {[f]} -> ?
1387-
signbit: Final[_ufunc_1_1] = ...
1420+
signbit: Final[_ufunc_1_1[_Call11Signbit]] = ...
1421+
1422+
# {?[uifc]Mm} -> ?
13881423
isfinite: Final[_ufunc_1_1[_Call11Bool]] = ...
13891424
isinf: Final[_ufunc_1_1[_Call11Bool]] = ...
13901425

test/static/accept/ufuncs.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ assert_type(np.spacing(f8), np.float64)
9696
assert_type(np.spacing(AR_f8), npt.NDArray[np.float64])
9797
assert_type(np.spacing(AR_f4), npt.NDArray[np.floating])
9898
assert_type(np.spacing(AR_f8, out=AR_f8), npt.NDArray[np.float64])
99+
100+
assert_type(np.signbit(f8), np.bool_)
101+
assert_type(np.signbit(AR_f8), npt.NDArray[np.bool_])
102+
assert_type(np.signbit(AR_f8, out=AR_bool), npt.NDArray[np.bool_])

test/static/reject/ufuncs.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ np.logical_xor(dt64, dt64, dtype=np.datetime64) # type: ignore[arg-type] # pyr
6363

6464
np.spacing(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
6565
np.spacing(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
66+
67+
np.signbit(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
68+
np.signbit(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]

0 commit comments

Comments
 (0)