Skip to content

Commit 059c896

Browse files
committed
🏷️ ufunc annotations for cbrt, deg2rad, degrees, fabs, rad2deg, radians
1 parent e402559 commit 059c896

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

src/numpy-stubs/_core/umath.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,12 +1454,13 @@ bitwise_count: Final[_ufunc_1_1] = ...
14541454
spacing: Final[_ufunc_1_1[_Call11Float]] = ...
14551455

14561456
# {[f]O} -> $1
1457-
cbrt: Final[_ufunc_1_1] = ...
1458-
deg2rad: Final[_ufunc_1_1] = ...
1459-
degrees: Final[_ufunc_1_1] = ...
1460-
fabs: Final[_ufunc_1_1] = ...
1461-
rad2deg: Final[_ufunc_1_1] = ...
1462-
radians: Final[_ufunc_1_1] = ...
1457+
# Note: https://github.com/numpy/numtype/pull/373#pullrequestreview-2708079543
1458+
cbrt: Final[_ufunc_1_1[_Call11Float]] = ...
1459+
deg2rad: Final[_ufunc_1_1[_Call11Float]] = ...
1460+
degrees: Final[_ufunc_1_1[_Call11Float]] = ...
1461+
fabs: Final[_ufunc_1_1[_Call11Float]] = ...
1462+
rad2deg: Final[_ufunc_1_1[_Call11Float]] = ...
1463+
radians: Final[_ufunc_1_1[_Call11Float]] = ...
14631464

14641465
# {[fc]O} -> $1
14651466
arccos: Final[_ufunc_1_1] = ...

test/static/accept/ufuncs.pyi

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,33 @@ assert_type(np.spacing(AR_f8, out=AR_f8), npt.NDArray[np.float64])
100100
assert_type(np.signbit(f8), np.bool_)
101101
assert_type(np.signbit(AR_f8), npt.NDArray[np.bool_])
102102
assert_type(np.signbit(AR_f8, out=AR_bool), npt.NDArray[np.bool_])
103+
104+
assert_type(np.cbrt(f8), np.float64)
105+
assert_type(np.cbrt(f8, dtype=np.float64), np.float64)
106+
assert_type(np.cbrt(AR_f8), npt.NDArray[np.float64])
107+
assert_type(np.cbrt(AR_f8, out=AR_f8), npt.NDArray[np.float64])
108+
109+
assert_type(np.deg2rad(f8), np.float64)
110+
assert_type(np.deg2rad(f8, dtype=np.float64), np.float64)
111+
assert_type(np.deg2rad(AR_f8), npt.NDArray[np.float64])
112+
assert_type(np.deg2rad(AR_f8, out=AR_f8), npt.NDArray[np.float64])
113+
114+
assert_type(np.degrees(f8), np.float64)
115+
assert_type(np.degrees(f8, dtype=np.float64), np.float64)
116+
assert_type(np.degrees(AR_f8), npt.NDArray[np.float64])
117+
assert_type(np.degrees(AR_f8, out=AR_f8), npt.NDArray[np.float64])
118+
119+
assert_type(np.fabs(f8), np.float64)
120+
assert_type(np.fabs(f8, dtype=np.float64), np.float64)
121+
assert_type(np.fabs(AR_f8), npt.NDArray[np.float64])
122+
assert_type(np.fabs(AR_f8, out=AR_f8), npt.NDArray[np.float64])
123+
124+
assert_type(np.rad2deg(f8), np.float64)
125+
assert_type(np.rad2deg(f8, dtype=np.float64), np.float64)
126+
assert_type(np.rad2deg(AR_f8), npt.NDArray[np.float64])
127+
assert_type(np.rad2deg(AR_f8, out=AR_f8), npt.NDArray[np.float64])
128+
129+
assert_type(np.radians(f8), np.float64)
130+
assert_type(np.radians(f8, dtype=np.float64), np.float64)
131+
assert_type(np.radians(AR_f8), npt.NDArray[np.float64])
132+
assert_type(np.radians(AR_f8, out=AR_f8), npt.NDArray[np.float64])

test/static/reject/ufuncs.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,21 @@ np.spacing(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ign
6666

6767
np.signbit(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
6868
np.signbit(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
69+
70+
np.cbrt(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
71+
np.cbrt(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
72+
73+
np.deg2rad(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
74+
np.deg2rad(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
75+
76+
np.degrees(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
77+
np.degrees(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
78+
79+
np.fabs(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
80+
np.fabs(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
81+
82+
np.rad2deg(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
83+
np.rad2deg(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]
84+
85+
np.radians(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]
86+
np.radians(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]

0 commit comments

Comments
 (0)