From 92cc699ecd974375d0b2e78d3dae255bdfffe6a4 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Sun, 30 Nov 2025 21:01:27 +0000 Subject: [PATCH] use np_ndarray_intp, np_ndarray_int64, np_ndarray_float aliases more --- pandas-stubs/core/groupby/ops.pyi | 6 ++---- pandas-stubs/core/indexes/interval.pyi | 3 ++- tests/__init__.py | 5 +++++ tests/indexes/arithmetic/bool/test_add.py | 7 +++++-- tests/indexes/arithmetic/bool/test_mul.py | 3 ++- tests/indexes/arithmetic/bool/test_sub.py | 3 ++- tests/indexes/arithmetic/complex/test_add.py | 7 +++++-- tests/indexes/arithmetic/complex/test_mul.py | 3 ++- tests/indexes/arithmetic/complex/test_sub.py | 7 +++++-- tests/indexes/arithmetic/float/test_add.py | 7 +++++-- tests/indexes/arithmetic/float/test_mul.py | 3 ++- tests/indexes/arithmetic/float/test_sub.py | 7 +++++-- tests/indexes/arithmetic/int/test_add.py | 7 +++++-- tests/indexes/arithmetic/int/test_mul.py | 3 ++- tests/indexes/arithmetic/int/test_sub.py | 7 +++++-- tests/indexes/arithmetic/str/test_add.py | 3 ++- tests/indexes/arithmetic/str/test_mul.py | 3 ++- .../arithmetic/timedeltaindex/test_floordiv.py | 5 +++-- tests/indexes/arithmetic/timedeltaindex/test_mul.py | 5 ++--- tests/scalars/test_scalars.py | 11 +++++++---- tests/series/arithmetic/bool/test_add.py | 7 +++++-- tests/series/arithmetic/bool/test_mul.py | 3 ++- tests/series/arithmetic/bool/test_sub.py | 3 ++- tests/series/arithmetic/complex/test_add.py | 7 +++++-- tests/series/arithmetic/complex/test_mul.py | 3 ++- tests/series/arithmetic/complex/test_sub.py | 7 +++++-- tests/series/arithmetic/float/test_add.py | 7 +++++-- tests/series/arithmetic/float/test_mul.py | 3 ++- tests/series/arithmetic/float/test_sub.py | 7 +++++-- tests/series/arithmetic/int/test_add.py | 7 +++++-- tests/series/arithmetic/int/test_mul.py | 3 ++- tests/series/arithmetic/int/test_sub.py | 7 +++++-- tests/series/arithmetic/str/test_add.py | 3 ++- tests/series/arithmetic/str/test_mul.py | 3 ++- tests/series/arithmetic/timedelta/test_floordiv.py | 5 +++-- tests/series/arithmetic/timedelta/test_mul.py | 3 ++- 36 files changed, 124 insertions(+), 59 deletions(-) diff --git a/pandas-stubs/core/groupby/ops.pyi b/pandas-stubs/core/groupby/ops.pyi index df5cb379a..584628a41 100644 --- a/pandas-stubs/core/groupby/ops.pyi +++ b/pandas-stubs/core/groupby/ops.pyi @@ -5,17 +5,15 @@ from typing import ( Generic, ) -import numpy as np - from pandas._typing import ( AxisInt, NDFrameT, - npt, + np_ndarray_intp, ) class DataSplitter(Generic[NDFrameT]): data: NDFrameT - labels: npt.NDArray[np.intp] + labels: np_ndarray_intp ngroups: int axis: AxisInt def __iter__(self) -> Iterator[NDFrameT]: ... diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index 186a7a0a1..73420e752 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -31,6 +31,7 @@ from pandas._typing import ( np_ndarray_bool, np_ndarray_dt, np_ndarray_int64, + np_ndarray_intp, np_ndarray_td, npt, ) @@ -41,7 +42,7 @@ _EdgesInt: TypeAlias = ( Sequence[int] | np_ndarray_int64 | npt.NDArray[np.int32] - | npt.NDArray[np.intp] + | np_ndarray_intp | pd.Series[int] | Index[int] ) diff --git a/tests/__init__.py b/tests/__init__.py index facc36a8a..a6ce47d9c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -68,9 +68,12 @@ np_1darray_td as np_1darray_td, np_2darray as np_2darray, np_ndarray as np_ndarray, + np_ndarray_anyint as np_ndarray_anyint, np_ndarray_bool as np_ndarray_bool, np_ndarray_dt as np_ndarray_dt, + np_ndarray_float as np_ndarray_float, np_ndarray_int as np_ndarray_int, + np_ndarray_int64 as np_ndarray_int64, np_ndarray_intp as np_ndarray_intp, np_ndarray_num as np_ndarray_num, np_ndarray_str as np_ndarray_str, @@ -457,6 +460,8 @@ np_ndarray_int: TypeAlias = npt.NDArray[np.signedinteger] np_ndarray_intp: TypeAlias = npt.NDArray[np.intp] np_ndarray_int64: TypeAlias = npt.NDArray[np.int64] + np_ndarray_anyint: TypeAlias = npt.NDArray[np.integer] + np_ndarray_float: TypeAlias = npt.NDArray[np.floating] np_ndarray_num: TypeAlias = npt.NDArray[np.number] np_ndarray_str: TypeAlias = npt.NDArray[np.str_] np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64] diff --git a/tests/indexes/arithmetic/bool/test_add.py b/tests/indexes/arithmetic/bool/test_add.py index b80a25b1d..8dc5fb6fb 100644 --- a/tests/indexes/arithmetic/bool/test_add.py +++ b/tests/indexes/arithmetic/bool/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([True, True, False]) @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(i + left, np_ndarray_int64), pd.Index, np.integer) check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c + left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/bool/test_mul.py b/tests/indexes/arithmetic/bool/test_mul.py index a1980eb72..aa232cd54 100644 --- a/tests/indexes/arithmetic/bool/test_mul.py +++ b/tests/indexes/arithmetic/bool/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Index` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(i * left, np_ndarray_int64), pd.Index, np.integer) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c * left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/bool/test_sub.py b/tests/indexes/arithmetic/bool/test_sub.py index faac659dd..e30a0676f 100644 --- a/tests/indexes/arithmetic/bool/test_sub.py +++ b/tests/indexes/arithmetic/bool/test_sub.py @@ -9,6 +9,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) left = pd.Index([True, True, False]) # left operand @@ -66,7 +67,7 @@ def test_sub_numpy_array() -> None: # `Index`es with the correct element type. if TYPE_CHECKING_INVALID_USAGE: assert_type(b - left, Never) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(i - left, np_ndarray_int64), pd.Index, np.integer) check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c - left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/complex/test_add.py b/tests/indexes/arithmetic/complex/test_add.py index bf3f6a4c2..681c2b97c 100644 --- a/tests/indexes/arithmetic/complex/test_add.py +++ b/tests/indexes/arithmetic/complex/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([1j, 2j, 3j]) @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating) + check(assert_type(i + left, np_ndarray_int64), pd.Index, np.complexfloating) check( assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating ) diff --git a/tests/indexes/arithmetic/complex/test_mul.py b/tests/indexes/arithmetic/complex/test_mul.py index 1d0c88f65..622384ae3 100644 --- a/tests/indexes/arithmetic/complex/test_mul.py +++ b/tests/indexes/arithmetic/complex/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Index` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating) + check(assert_type(i * left, np_ndarray_int64), pd.Index, np.complexfloating) check( assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating ) diff --git a/tests/indexes/arithmetic/complex/test_sub.py b/tests/indexes/arithmetic/complex/test_sub.py index 8df2892d1..5c97705cc 100644 --- a/tests/indexes/arithmetic/complex/test_sub.py +++ b/tests/indexes/arithmetic/complex/test_sub.py @@ -5,7 +5,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([1j, 2j, 3j]) @@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b - left, NoReturn), pd.Index, np.complexfloating) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating) + check(assert_type(i - left, np_ndarray_int64), pd.Index, np.complexfloating) check( assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating ) diff --git a/tests/indexes/arithmetic/float/test_add.py b/tests/indexes/arithmetic/float/test_add.py index ce5a84f1f..f2f7f5c54 100644 --- a/tests/indexes/arithmetic/float/test_add.py +++ b/tests/indexes/arithmetic/float/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([1.0, 2.0, 3.0]) @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.floating) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.floating) + check(assert_type(i + left, np_ndarray_int64), pd.Index, np.floating) check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c + left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/float/test_mul.py b/tests/indexes/arithmetic/float/test_mul.py index 67f4d5f5d..9c5c5bdc9 100644 --- a/tests/indexes/arithmetic/float/test_mul.py +++ b/tests/indexes/arithmetic/float/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Index` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.floating) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.floating) + check(assert_type(i * left, np_ndarray_int64), pd.Index, np.floating) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c * left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/float/test_sub.py b/tests/indexes/arithmetic/float/test_sub.py index c35a7a5a6..c19f37ec5 100644 --- a/tests/indexes/arithmetic/float/test_sub.py +++ b/tests/indexes/arithmetic/float/test_sub.py @@ -5,7 +5,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([1.0, 2.0, 3.0]) @@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b - left, NoReturn), pd.Index, np.floating) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.floating) + check(assert_type(i - left, np_ndarray_int64), pd.Index, np.floating) check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c - left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/int/test_add.py b/tests/indexes/arithmetic/int/test_add.py index 2d3cc7c1d..964c913ab 100644 --- a/tests/indexes/arithmetic/int/test_add.py +++ b/tests/indexes/arithmetic/int/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([1, 2, 3]) @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.integer) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(i + left, np_ndarray_int64), pd.Index, np.integer) check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c + left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/int/test_mul.py b/tests/indexes/arithmetic/int/test_mul.py index b7f4d0b7c..641ce71f6 100644 --- a/tests/indexes/arithmetic/int/test_mul.py +++ b/tests/indexes/arithmetic/int/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -92,7 +93,7 @@ def test_mul_numpy_array(left: "pd.Index[int]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Index` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Index, np.integer) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(i * left, np_ndarray_int64), pd.Index, np.integer) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c * left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/int/test_sub.py b/tests/indexes/arithmetic/int/test_sub.py index dfc151b2e..13b64fb5d 100644 --- a/tests/indexes/arithmetic/int/test_sub.py +++ b/tests/indexes/arithmetic/int/test_sub.py @@ -5,7 +5,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) # left operand left = pd.Index([1, 2, 3]) @@ -57,7 +60,7 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `Index`es with the correct element type. check(assert_type(b - left, NoReturn), pd.Index, np.integer) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(i - left, np_ndarray_int64), pd.Index, np.integer) check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( assert_type(c - left, "npt.NDArray[np.complex128]"), diff --git a/tests/indexes/arithmetic/str/test_add.py b/tests/indexes/arithmetic/str/test_add.py index d4783f98f..b662e9030 100644 --- a/tests/indexes/arithmetic/str/test_add.py +++ b/tests/indexes/arithmetic/str/test_add.py @@ -12,6 +12,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) left = pd.Index(["1", "23", "456"]) # left operand @@ -61,7 +62,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Index`es. if TYPE_CHECKING_INVALID_USAGE: - assert_type(i + left, "npt.NDArray[np.int64]") + assert_type(i + left, np_ndarray_int64) if sys.version_info >= (3, 11): # `numpy` typing gives `npt.NDArray[np.int64]` in the static type # checking, where our `__radd__` cannot override. At runtime, they return diff --git a/tests/indexes/arithmetic/str/test_mul.py b/tests/indexes/arithmetic/str/test_mul.py index ea3206a9a..1eb32698f 100644 --- a/tests/indexes/arithmetic/str/test_mul.py +++ b/tests/indexes/arithmetic/str/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -98,7 +99,7 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None: # `Index` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: assert_type(b * left, "npt.NDArray[np.bool_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, str) + check(assert_type(i * left, np_ndarray_int64), pd.Index, str) if TYPE_CHECKING_INVALID_USAGE: assert_type(f * left, "npt.NDArray[np.float64]") assert_type(c * left, "npt.NDArray[np.complex128]") diff --git a/tests/indexes/arithmetic/timedeltaindex/test_floordiv.py b/tests/indexes/arithmetic/timedeltaindex/test_floordiv.py index ab2e7cb8e..5a01b57bb 100644 --- a/tests/indexes/arithmetic/timedeltaindex/test_floordiv.py +++ b/tests/indexes/arithmetic/timedeltaindex/test_floordiv.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -95,11 +96,11 @@ def test_floordiv_numpy_array(left: pd.TimedeltaIndex) -> None: # errors or pd.Series. if TYPE_CHECKING_INVALID_USAGE: assert_type(b // left, "npt.NDArray[np.int8]") - assert_type(i // left, "npt.NDArray[np.int64]") + assert_type(i // left, np_ndarray_int64) assert_type(f // left, "npt.NDArray[np.float64]") assert_type(c // left, Any) assert_type(s // left, Any) - check(assert_type(d // left, "npt.NDArray[np.int64]"), pd.Index, np.integer) + check(assert_type(d // left, np_ndarray_int64), pd.Index, np.integer) def test_floordiv_pd_scalar(left: pd.TimedeltaIndex) -> None: diff --git a/tests/indexes/arithmetic/timedeltaindex/test_mul.py b/tests/indexes/arithmetic/timedeltaindex/test_mul.py index 1ed7501cb..2d7e8b130 100644 --- a/tests/indexes/arithmetic/timedeltaindex/test_mul.py +++ b/tests/indexes/arithmetic/timedeltaindex/test_mul.py @@ -10,6 +10,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -78,9 +79,7 @@ def test_mul_numpy_array(left: pd.TimedeltaIndex) -> None: if TYPE_CHECKING_INVALID_USAGE: # We made it Never, but numpy takes over assert_type(b * left, "npt.NDArray[np.bool_]") - check( - assert_type(i * left, "npt.NDArray[np.int64]"), pd.TimedeltaIndex, pd.Timedelta - ) + check(assert_type(i * left, np_ndarray_int64), pd.TimedeltaIndex, pd.Timedelta) check( assert_type(f * left, "npt.NDArray[np.float64]"), pd.TimedeltaIndex, diff --git a/tests/scalars/test_scalars.py b/tests/scalars/test_scalars.py index 36c7f59fc..81bd9b7ae 100644 --- a/tests/scalars/test_scalars.py +++ b/tests/scalars/test_scalars.py @@ -10,7 +10,6 @@ import dateutil.tz import numpy as np -from numpy import typing as npt import pandas as pd from pandas.api.typing import NaTType import pytz @@ -19,7 +18,9 @@ ) from pandas._libs.tslibs.timedeltas import Components -from pandas._typing import TimeUnit +from pandas._typing import ( + TimeUnit, +) from tests import ( PD_LTE_23, @@ -28,8 +29,10 @@ np_1darray_bool, np_2darray, np_ndarray, + np_ndarray_anyint, np_ndarray_bool, np_ndarray_dt, + np_ndarray_float, np_ndarray_td, pytest_warns_bounded, ) @@ -619,8 +622,8 @@ def test_timedelta_add_sub() -> None: def test_timedelta_mul_div() -> None: td = pd.Timedelta("1 day") - np_intp_arr: npt.NDArray[np.integer] = np.array([1, 2, 3]) - np_float_arr: npt.NDArray[np.floating] = np.array([1.2, 2.2, 3.4]) + np_intp_arr: np_ndarray_anyint = np.array([1, 2, 3]) + np_float_arr: np_ndarray_float = np.array([1.2, 2.2, 3.4]) md_int = 3 md_float = 3.5 diff --git a/tests/series/arithmetic/bool/test_add.py b/tests/series/arithmetic/bool/test_add.py index cd3959d08..9774e0ce7 100644 --- a/tests/series/arithmetic/bool/test_add.py +++ b/tests/series/arithmetic/bool/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([True, True, False]) # left operand @@ -78,7 +81,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Series, np.bool_) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(i + left, np_ndarray_int64), pd.Series, np.integer) check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c + left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/bool/test_mul.py b/tests/series/arithmetic/bool/test_mul.py index e9dcf9d79..52a3299e6 100644 --- a/tests/series/arithmetic/bool/test_mul.py +++ b/tests/series/arithmetic/bool/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -128,7 +129,7 @@ def test_mul_numpy_array(left: "pd.Series[bool]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Series, np.bool_) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(i * left, np_ndarray_int64), pd.Series, np.integer) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c * left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/bool/test_sub.py b/tests/series/arithmetic/bool/test_sub.py index 6517e253f..39da9daad 100644 --- a/tests/series/arithmetic/bool/test_sub.py +++ b/tests/series/arithmetic/bool/test_sub.py @@ -9,6 +9,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) left = pd.Series([True, True, False]) # left operand @@ -94,7 +95,7 @@ def test_sub_numpy_array() -> None: # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: assert_type(b - left, Never) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(i - left, np_ndarray_int64), pd.Series, np.integer) check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c - left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/complex/test_add.py b/tests/series/arithmetic/complex/test_add.py index 4e0338979..ca12d6a45 100644 --- a/tests/series/arithmetic/complex/test_add.py +++ b/tests/series/arithmetic/complex/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([1j, 2j, 3j]) # left operand @@ -90,7 +93,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Series, np.complexfloating) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Series, np.complexfloating) + check(assert_type(i + left, np_ndarray_int64), pd.Series, np.complexfloating) check( assert_type(f + left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating ) diff --git a/tests/series/arithmetic/complex/test_mul.py b/tests/series/arithmetic/complex/test_mul.py index abd2056e5..c66e21a69 100644 --- a/tests/series/arithmetic/complex/test_mul.py +++ b/tests/series/arithmetic/complex/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -140,7 +141,7 @@ def test_mul_numpy_array(left: "pd.Series[complex]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Series, np.complexfloating) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, np.complexfloating) + check(assert_type(i * left, np_ndarray_int64), pd.Series, np.complexfloating) check( assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating ) diff --git a/tests/series/arithmetic/complex/test_sub.py b/tests/series/arithmetic/complex/test_sub.py index a58c31ae3..f2bdc4300 100644 --- a/tests/series/arithmetic/complex/test_sub.py +++ b/tests/series/arithmetic/complex/test_sub.py @@ -5,7 +5,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([1j, 2j, 3j]) # left operand @@ -92,7 +95,7 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b - left, NoReturn), pd.Series, np.complexfloating) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Series, np.complexfloating) + check(assert_type(i - left, np_ndarray_int64), pd.Series, np.complexfloating) check( assert_type(f - left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating ) diff --git a/tests/series/arithmetic/float/test_add.py b/tests/series/arithmetic/float/test_add.py index 6318ebf24..cf927973e 100644 --- a/tests/series/arithmetic/float/test_add.py +++ b/tests/series/arithmetic/float/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([1.0, 2.0, 3.0]) # left operand @@ -78,7 +81,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Series, np.floating) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Series, np.floating) + check(assert_type(i + left, np_ndarray_int64), pd.Series, np.floating) check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c + left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/float/test_mul.py b/tests/series/arithmetic/float/test_mul.py index d83468c06..ef3c5ddb6 100644 --- a/tests/series/arithmetic/float/test_mul.py +++ b/tests/series/arithmetic/float/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -128,7 +129,7 @@ def test_mul_numpy_array(left: "pd.Series[float]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Series, np.floating) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, np.floating) + check(assert_type(i * left, np_ndarray_int64), pd.Series, np.floating) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c * left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/float/test_sub.py b/tests/series/arithmetic/float/test_sub.py index afad8dab5..75c885eaa 100644 --- a/tests/series/arithmetic/float/test_sub.py +++ b/tests/series/arithmetic/float/test_sub.py @@ -5,7 +5,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([1.0, 2.0, 3.0]) # left operand @@ -80,7 +83,7 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b - left, NoReturn), pd.Series, np.floating) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Series, np.floating) + check(assert_type(i - left, np_ndarray_int64), pd.Series, np.floating) check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c - left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/int/test_add.py b/tests/series/arithmetic/int/test_add.py index 8f544374a..9a226f338 100644 --- a/tests/series/arithmetic/int/test_add.py +++ b/tests/series/arithmetic/int/test_add.py @@ -3,7 +3,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([1, 2, 3]) # left operand @@ -78,7 +81,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Series, np.integer) - check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(i + left, np_ndarray_int64), pd.Series, np.integer) check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c + left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/int/test_mul.py b/tests/series/arithmetic/int/test_mul.py index e3c1c7f05..b0d7d85d7 100644 --- a/tests/series/arithmetic/int/test_mul.py +++ b/tests/series/arithmetic/int/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -128,7 +129,7 @@ def test_mul_numpy_array(left: "pd.Series[int]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Series, np.integer) - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(i * left, np_ndarray_int64), pd.Series, np.integer) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c * left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/int/test_sub.py b/tests/series/arithmetic/int/test_sub.py index 28bcdd4f0..c43786413 100644 --- a/tests/series/arithmetic/int/test_sub.py +++ b/tests/series/arithmetic/int/test_sub.py @@ -5,7 +5,10 @@ import pandas as pd from typing_extensions import assert_type -from tests import check +from tests import ( + check, + np_ndarray_int64, +) left = pd.Series([1, 2, 3]) # left operand @@ -80,7 +83,7 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `Series` with the correct element type. check(assert_type(b - left, NoReturn), pd.Series, np.integer) - check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(i - left, np_ndarray_int64), pd.Series, np.integer) check(assert_type(f - left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( assert_type(c - left, "npt.NDArray[np.complex128]"), diff --git a/tests/series/arithmetic/str/test_add.py b/tests/series/arithmetic/str/test_add.py index 78986f1ca..553adc676 100644 --- a/tests/series/arithmetic/str/test_add.py +++ b/tests/series/arithmetic/str/test_add.py @@ -12,6 +12,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) left = pd.Series(["1", "23", "456"]) # left operand @@ -79,7 +80,7 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Series`. if TYPE_CHECKING_INVALID_USAGE: - assert_type(i + left, "npt.NDArray[np.int64]") + assert_type(i + left, np_ndarray_int64) if sys.version_info >= (3, 11): # `numpy` typing gives `npt.NDArray[np.int64]` in the static type # checking, where our `__radd__` cannot override. At runtime, they return diff --git a/tests/series/arithmetic/str/test_mul.py b/tests/series/arithmetic/str/test_mul.py index ef272db26..fc888b5f9 100644 --- a/tests/series/arithmetic/str/test_mul.py +++ b/tests/series/arithmetic/str/test_mul.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -134,7 +135,7 @@ def test_mul_numpy_array(left: "pd.Series[str]") -> None: # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: assert_type(b * left, "npt.NDArray[np.bool_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, str) + check(assert_type(i * left, np_ndarray_int64), pd.Series, str) if TYPE_CHECKING_INVALID_USAGE: assert_type(f * left, "npt.NDArray[np.float64]") assert_type(c * left, "npt.NDArray[np.complex128]") diff --git a/tests/series/arithmetic/timedelta/test_floordiv.py b/tests/series/arithmetic/timedelta/test_floordiv.py index eb9a9935d..0f5a97d0a 100644 --- a/tests/series/arithmetic/timedelta/test_floordiv.py +++ b/tests/series/arithmetic/timedelta/test_floordiv.py @@ -16,6 +16,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -145,11 +146,11 @@ def test_floordiv_numpy_array(left: "pd.Series[pd.Timedelta]") -> None: # errors or pd.Series. if TYPE_CHECKING_INVALID_USAGE: assert_type(b // left, "npt.NDArray[np.int8]") - assert_type(i // left, "npt.NDArray[np.int64]") + assert_type(i // left, np_ndarray_int64) assert_type(f // left, "npt.NDArray[np.float64]") assert_type(c // left, Any) assert_type(s // left, Any) - check(assert_type(d // left, "npt.NDArray[np.int64]"), pd.Series, np.integer) + check(assert_type(d // left, np_ndarray_int64), pd.Series, np.integer) if TYPE_CHECKING_INVALID_USAGE: left.floordiv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] diff --git a/tests/series/arithmetic/timedelta/test_mul.py b/tests/series/arithmetic/timedelta/test_mul.py index 2add38111..0b151fcce 100644 --- a/tests/series/arithmetic/timedelta/test_mul.py +++ b/tests/series/arithmetic/timedelta/test_mul.py @@ -10,6 +10,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + np_ndarray_int64, ) @@ -105,7 +106,7 @@ def test_mul_numpy_array(left: "pd.Series[pd.Timedelta]") -> None: # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: assert_type(b * left, "npt.NDArray[np.bool_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, pd.Timedelta) + check(assert_type(i * left, np_ndarray_int64), pd.Series, pd.Timedelta) check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: # We made it Never, but numpy takes over