From 059c896d19c762da9cbb657949505ab3fdd9f9cf Mon Sep 17 00:00:00 2001 From: GUAN MING Date: Sun, 23 Mar 2025 00:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20ufunc=20annotations=20f?= =?UTF-8?q?or=20`cbrt`,=20`deg2rad`,=20`degrees`,=20`fabs`,=20`rad2deg`,?= =?UTF-8?q?=20`radians`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/umath.pyi | 13 +++++++------ test/static/accept/ufuncs.pyi | 30 ++++++++++++++++++++++++++++++ test/static/reject/ufuncs.pyi | 18 ++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/numpy-stubs/_core/umath.pyi b/src/numpy-stubs/_core/umath.pyi index 7a9227cf..ba8d0fd7 100644 --- a/src/numpy-stubs/_core/umath.pyi +++ b/src/numpy-stubs/_core/umath.pyi @@ -1454,12 +1454,13 @@ bitwise_count: Final[_ufunc_1_1] = ... spacing: Final[_ufunc_1_1[_Call11Float]] = ... # {[f]O} -> $1 -cbrt: Final[_ufunc_1_1] = ... -deg2rad: Final[_ufunc_1_1] = ... -degrees: Final[_ufunc_1_1] = ... -fabs: Final[_ufunc_1_1] = ... -rad2deg: Final[_ufunc_1_1] = ... -radians: Final[_ufunc_1_1] = ... +# Note: https://github.com/numpy/numtype/pull/373#pullrequestreview-2708079543 +cbrt: Final[_ufunc_1_1[_Call11Float]] = ... +deg2rad: Final[_ufunc_1_1[_Call11Float]] = ... +degrees: Final[_ufunc_1_1[_Call11Float]] = ... +fabs: Final[_ufunc_1_1[_Call11Float]] = ... +rad2deg: Final[_ufunc_1_1[_Call11Float]] = ... +radians: Final[_ufunc_1_1[_Call11Float]] = ... # {[fc]O} -> $1 arccos: Final[_ufunc_1_1] = ... diff --git a/test/static/accept/ufuncs.pyi b/test/static/accept/ufuncs.pyi index 22908343..9afc6d18 100644 --- a/test/static/accept/ufuncs.pyi +++ b/test/static/accept/ufuncs.pyi @@ -100,3 +100,33 @@ 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_]) + +assert_type(np.cbrt(f8), np.float64) +assert_type(np.cbrt(f8, dtype=np.float64), np.float64) +assert_type(np.cbrt(AR_f8), npt.NDArray[np.float64]) +assert_type(np.cbrt(AR_f8, out=AR_f8), npt.NDArray[np.float64]) + +assert_type(np.deg2rad(f8), np.float64) +assert_type(np.deg2rad(f8, dtype=np.float64), np.float64) +assert_type(np.deg2rad(AR_f8), npt.NDArray[np.float64]) +assert_type(np.deg2rad(AR_f8, out=AR_f8), npt.NDArray[np.float64]) + +assert_type(np.degrees(f8), np.float64) +assert_type(np.degrees(f8, dtype=np.float64), np.float64) +assert_type(np.degrees(AR_f8), npt.NDArray[np.float64]) +assert_type(np.degrees(AR_f8, out=AR_f8), npt.NDArray[np.float64]) + +assert_type(np.fabs(f8), np.float64) +assert_type(np.fabs(f8, dtype=np.float64), np.float64) +assert_type(np.fabs(AR_f8), npt.NDArray[np.float64]) +assert_type(np.fabs(AR_f8, out=AR_f8), npt.NDArray[np.float64]) + +assert_type(np.rad2deg(f8), np.float64) +assert_type(np.rad2deg(f8, dtype=np.float64), np.float64) +assert_type(np.rad2deg(AR_f8), npt.NDArray[np.float64]) +assert_type(np.rad2deg(AR_f8, out=AR_f8), npt.NDArray[np.float64]) + +assert_type(np.radians(f8), np.float64) +assert_type(np.radians(f8, dtype=np.float64), np.float64) +assert_type(np.radians(AR_f8), npt.NDArray[np.float64]) +assert_type(np.radians(AR_f8, out=AR_f8), npt.NDArray[np.float64]) diff --git a/test/static/reject/ufuncs.pyi b/test/static/reject/ufuncs.pyi index 59adb9bd..cdb00dd6 100644 --- a/test/static/reject/ufuncs.pyi +++ b/test/static/reject/ufuncs.pyi @@ -66,3 +66,21 @@ np.spacing(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ign 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] + +np.cbrt(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.cbrt(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] + +np.deg2rad(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.deg2rad(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] + +np.degrees(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.degrees(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] + +np.fabs(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.fabs(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] + +np.rad2deg(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.rad2deg(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] + +np.radians(dt64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] +np.radians(AR_f8, dtype=np.datetime64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue]