From ecb72034e85abe21a722d885a8735774149ad245 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 1 Dec 2025 10:30:23 +0000 Subject: [PATCH] Use np array aliases in tests --- pandas-stubs/_typing.pyi | 2 +- pandas-stubs/core/base.pyi | 5 +++-- pandas-stubs/core/indexes/accessors.pyi | 17 ++++++++--------- pandas-stubs/core/indexes/period.pyi | 4 ++-- tests/indexes/arithmetic/bool/test_add.py | 11 ++++++++--- tests/indexes/arithmetic/bool/test_mul.py | 10 +++++++--- tests/indexes/arithmetic/complex/test_add.py | 7 +++++-- tests/indexes/arithmetic/complex/test_mul.py | 10 +++++++--- tests/indexes/arithmetic/float/test_add.py | 11 ++++++++--- tests/indexes/arithmetic/float/test_floordiv.py | 14 ++++++++------ tests/indexes/arithmetic/float/test_mul.py | 10 +++++++--- tests/indexes/arithmetic/int/test_add.py | 11 ++++++++--- tests/indexes/arithmetic/int/test_floordiv.py | 14 ++++++++------ tests/indexes/arithmetic/int/test_mul.py | 10 +++++++--- tests/indexes/arithmetic/str/test_add.py | 8 +++++--- tests/indexes/arithmetic/str/test_mul.py | 10 +++++++--- .../arithmetic/timedeltaindex/test_mul.py | 7 +++++-- tests/series/arithmetic/bool/test_add.py | 7 +++++-- tests/series/arithmetic/bool/test_mul.py | 10 +++++++--- tests/series/arithmetic/complex/test_add.py | 7 +++++-- tests/series/arithmetic/complex/test_mul.py | 10 +++++++--- tests/series/arithmetic/float/test_add.py | 7 +++++-- tests/series/arithmetic/float/test_floordiv.py | 7 ++++--- tests/series/arithmetic/float/test_mul.py | 10 +++++++--- tests/series/arithmetic/int/test_add.py | 11 ++++++++--- tests/series/arithmetic/int/test_floordiv.py | 16 ++++++++-------- tests/series/arithmetic/int/test_mul.py | 10 +++++++--- tests/series/arithmetic/str/test_add.py | 8 +++++--- tests/series/arithmetic/str/test_mul.py | 10 +++++++--- tests/series/arithmetic/test_sub.py | 4 ++-- tests/series/arithmetic/timedelta/test_add.py | 9 ++++++--- tests/series/arithmetic/timedelta/test_mul.py | 7 +++++-- tests/series/arithmetic/timedelta/test_sub.py | 9 ++++++--- tests/series/arithmetic/timestamp/test_add.py | 9 ++++++--- tests/series/arithmetic/timestamp/test_sub.py | 9 ++++++--- 35 files changed, 210 insertions(+), 111 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 018c3443b..1350b7c1b 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -827,7 +827,7 @@ TimeNonexistent: TypeAlias = ( DropKeep: TypeAlias = Literal["first", "last", False] CorrelationMethod: TypeAlias = ( Literal["pearson", "kendall", "spearman"] - | Callable[[np.typing.NDArray[Any], np.typing.NDArray[Any]], float] + | Callable[[npt.NDArray[Any], npt.NDArray[Any]], float] ) AlignJoin: TypeAlias = Literal["outer", "inner", "left", "right"] DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"] diff --git a/pandas-stubs/core/base.pyi b/pandas-stubs/core/base.pyi index 1dc1d1c2c..ec9a22f39 100644 --- a/pandas-stubs/core/base.pyi +++ b/pandas-stubs/core/base.pyi @@ -18,6 +18,7 @@ from typing import ( from _typeshed import _T_contra import numpy as np +import numpy.typing as npt from pandas.core.arraylike import OpsMixin from pandas.core.arrays import ExtensionArray from pandas.core.arrays.categorical import Categorical @@ -222,7 +223,7 @@ ScalarArrayIndexReal: TypeAlias = ( float | Sequence[float | NumpyRealScalar] | NumpyRealScalar - | np.typing.NDArray[NumpyRealScalar] + | npt.NDArray[NumpyRealScalar] | ExtensionArray | IndexReal ) @@ -235,7 +236,7 @@ ScalarArrayIndexComplex: TypeAlias = ( complex | Sequence[complex | NumpyComplexScalar] | NumpyComplexScalar - | np.typing.NDArray[NumpyComplexScalar] + | npt.NDArray[NumpyComplexScalar] | ExtensionArray | IndexComplex ) diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index 69441edb2..477d96d21 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -12,7 +12,6 @@ from typing import ( type_check_only, ) -import numpy as np from pandas.core.accessor import PandasDelegate from pandas.core.arrays.base import ExtensionArray from pandas.core.arrays.categorical import Categorical @@ -45,8 +44,8 @@ from pandas._typing import ( TimestampConvention, TimeUnit, TimeZones, - np_1darray, np_1darray_bool, + np_1darray_object, np_ndarray_bool, ) @@ -135,10 +134,10 @@ class _DatetimeObjectOps( ): ... _DTOtherOpsDateReturnType = TypeVar( - "_DTOtherOpsDateReturnType", bound=Series[date] | np_1darray[np.object_] + "_DTOtherOpsDateReturnType", bound=Series[date] | np_1darray_object ) _DTOtherOpsTimeReturnType = TypeVar( - "_DTOtherOpsTimeReturnType", bound=Series[time] | np_1darray[np.object_] + "_DTOtherOpsTimeReturnType", bound=Series[time] | np_1darray_object ) class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturnType]): @@ -293,7 +292,7 @@ class DatetimeProperties( _DTToPeriodReturnType, ], ): - def to_pydatetime(self) -> np_1darray[np.object_]: ... + def to_pydatetime(self) -> np_1darray_object: ... def isocalendar(self) -> DataFrame: ... @property def unit(self) -> TimeUnit: ... @@ -309,7 +308,7 @@ _TDTotalSecondsReturnType = TypeVar( class _TimedeltaPropertiesNoRounding( Generic[_TDNoRoundingMethodReturnType, _TDTotalSecondsReturnType] ): - def to_pytimedelta(self) -> np_1darray[np.object_]: ... + def to_pytimedelta(self) -> np_1darray_object: ... @property def components(self) -> DataFrame: ... @property @@ -418,8 +417,8 @@ class DatetimeIndexProperties( Index[int], np_1darray_bool, DatetimeIndex, - np_1darray[np.object_], - np_1darray[np.object_], + np_1darray_object, + np_1darray_object, BaseOffset, DatetimeIndex, Index, @@ -431,7 +430,7 @@ class DatetimeIndexProperties( def is_normalized(self) -> bool: ... @property def tzinfo(self) -> _tzinfo | None: ... - def to_pydatetime(self) -> np_1darray[np.object_]: ... + def to_pydatetime(self) -> np_1darray_object: ... def std( self, axis: int | None = ..., ddof: int = ..., skipna: bool = ... ) -> Timedelta: ... diff --git a/pandas-stubs/core/indexes/period.pyi b/pandas-stubs/core/indexes/period.pyi index b70fac3e4..4676fe1c8 100644 --- a/pandas-stubs/core/indexes/period.pyi +++ b/pandas-stubs/core/indexes/period.pyi @@ -22,8 +22,8 @@ from pandas._typing import ( AxesData, Dtype, Frequency, - np_1darray, np_1darray_intp, + np_1darray_object, np_ndarray_bool, ) @@ -37,7 +37,7 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField name: Hashable | None = None, ) -> Self: ... @property - def values(self) -> np_1darray[np.object_]: ... + def values(self) -> np_1darray_object: ... def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] self, other: datetime.timedelta ) -> Self: ... diff --git a/tests/indexes/arithmetic/bool/test_add.py b/tests/indexes/arithmetic/bool/test_add.py index df1ed455a..2294081b9 100644 --- a/tests/indexes/arithmetic/bool/test_add.py +++ b/tests/indexes/arithmetic/bool/test_add.py @@ -3,8 +3,13 @@ import pandas as pd from typing_extensions import assert_type -from tests import check -from tests._typing import np_ndarray_int64 +from tests import ( + check, +) +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) # left operand left = pd.Index([True, True, False]) @@ -55,7 +60,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), pd.Index, np.bool_) 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( diff --git a/tests/indexes/arithmetic/bool/test_mul.py b/tests/indexes/arithmetic/bool/test_mul.py index 51baf86e4..91986b39f 100644 --- a/tests/indexes/arithmetic/bool/test_mul.py +++ b/tests/indexes/arithmetic/bool/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), pd.Index, np.bool_) 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( @@ -102,7 +106,7 @@ def test_mul_numpy_array(left: "pd.Index[bool]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, np_ndarray_td) def test_mul_pd_index(left: "pd.Index[bool]") -> None: diff --git a/tests/indexes/arithmetic/complex/test_add.py b/tests/indexes/arithmetic/complex/test_add.py index 113a6973a..297d2095f 100644 --- a/tests/indexes/arithmetic/complex/test_add.py +++ b/tests/indexes/arithmetic/complex/test_add.py @@ -4,7 +4,10 @@ from typing_extensions import assert_type from tests import check -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) # left operand left = pd.Index([1j, 2j, 3j]) @@ -55,7 +58,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), 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 bc1637301..235265652 100644 --- a/tests/indexes/arithmetic/complex/test_mul.py +++ b/tests/indexes/arithmetic/complex/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), 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 @@ -104,7 +108,7 @@ def test_mul_numpy_array(left: "pd.Index[complex]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, np_ndarray_td) def test_mul_pd_index(left: "pd.Index[complex]") -> None: diff --git a/tests/indexes/arithmetic/float/test_add.py b/tests/indexes/arithmetic/float/test_add.py index 870c165e7..f5ba818f3 100644 --- a/tests/indexes/arithmetic/float/test_add.py +++ b/tests/indexes/arithmetic/float/test_add.py @@ -3,8 +3,13 @@ import pandas as pd from typing_extensions import assert_type -from tests import check -from tests._typing import np_ndarray_int64 +from tests import ( + check, +) +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) # left operand left = pd.Index([1.0, 2.0, 3.0]) @@ -55,7 +60,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), 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( diff --git a/tests/indexes/arithmetic/float/test_floordiv.py b/tests/indexes/arithmetic/float/test_floordiv.py index 502b148b6..78693a0a8 100644 --- a/tests/indexes/arithmetic/float/test_floordiv.py +++ b/tests/indexes/arithmetic/float/test_floordiv.py @@ -5,6 +5,7 @@ from typing import Any import numpy as np +import numpy.typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -16,6 +17,9 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_int64, +) @pytest.fixture @@ -92,16 +96,14 @@ def test_floordiv_numpy_array(left: "pd.Index[float]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rfloordiv__` cannot override. At runtime, they lead to # errors or pd.Index. - check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Index, np.floating) - check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Index, np.floating) - check( - assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Index, np.floating - ) + check(assert_type(b // left, "npt.NDArray[np.int8]"), 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) if TYPE_CHECKING_INVALID_USAGE: assert_type(c // left, Any) assert_type(s // left, Any) check( - assert_type(d // left, "np.typing.NDArray[np.int64]"), + assert_type(d // left, np_ndarray_int64), pd.TimedeltaIndex, pd.Timedelta, ) diff --git a/tests/indexes/arithmetic/float/test_mul.py b/tests/indexes/arithmetic/float/test_mul.py index d8810a228..b255f874f 100644 --- a/tests/indexes/arithmetic/float/test_mul.py +++ b/tests/indexes/arithmetic/float/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), 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( @@ -103,7 +107,7 @@ def test_mul_numpy_array(left: "pd.Index[float]") -> None: if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) check( - assert_type(d * left, "npt.NDArray[np.timedelta64]"), + assert_type(d * left, np_ndarray_td), pd.TimedeltaIndex, pd.Timedelta, ) diff --git a/tests/indexes/arithmetic/int/test_add.py b/tests/indexes/arithmetic/int/test_add.py index 1003d1c21..2e0ed836e 100644 --- a/tests/indexes/arithmetic/int/test_add.py +++ b/tests/indexes/arithmetic/int/test_add.py @@ -3,8 +3,13 @@ import pandas as pd from typing_extensions import assert_type -from tests import check -from tests._typing import np_ndarray_int64 +from tests import ( + check, +) +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) # left operand left = pd.Index([1, 2, 3]) @@ -55,7 +60,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), 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( diff --git a/tests/indexes/arithmetic/int/test_floordiv.py b/tests/indexes/arithmetic/int/test_floordiv.py index f1942d637..cb2a61bbe 100644 --- a/tests/indexes/arithmetic/int/test_floordiv.py +++ b/tests/indexes/arithmetic/int/test_floordiv.py @@ -5,6 +5,7 @@ from typing import Any import numpy as np +import numpy.typing as npt # noqa:F401 import pandas as pd import pytest from typing_extensions import ( @@ -16,6 +17,9 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_int64, +) @pytest.fixture @@ -92,16 +96,14 @@ def test_floordiv_numpy_array(left: "pd.Index[int]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rfloordiv__` cannot override. At runtime, they lead to # errors or pd.Index. - check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Index, np.integer) - check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Index, np.integer) - check( - assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Index, np.floating - ) + check(assert_type(b // left, "npt.NDArray[np.int8]"), 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) if TYPE_CHECKING_INVALID_USAGE: assert_type(c // left, Any) assert_type(s // left, Any) check( - assert_type(d // left, "np.typing.NDArray[np.int64]"), + assert_type(d // left, np_ndarray_int64), pd.TimedeltaIndex, pd.Timedelta, ) diff --git a/tests/indexes/arithmetic/int/test_mul.py b/tests/indexes/arithmetic/int/test_mul.py index 801a97971..42cbf7cea 100644 --- a/tests/indexes/arithmetic/int/test_mul.py +++ b/tests/indexes/arithmetic/int/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -92,7 +96,7 @@ def test_mul_numpy_array(left: "pd.Index[int]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), 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( @@ -102,7 +106,7 @@ def test_mul_numpy_array(left: "pd.Index[int]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - check(assert_type(d * left, "npt.NDArray[np.timedelta64]"), pd.Index, pd.Timedelta) + check(assert_type(d * left, np_ndarray_td), pd.Index, pd.Timedelta) def test_mul_pd_index(left: "pd.Index[int]") -> None: diff --git a/tests/indexes/arithmetic/str/test_add.py b/tests/indexes/arithmetic/str/test_add.py index 25f2573df..7d7fbab02 100644 --- a/tests/indexes/arithmetic/str/test_add.py +++ b/tests/indexes/arithmetic/str/test_add.py @@ -2,7 +2,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import ( Never, @@ -13,7 +12,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_int64, + np_ndarray_str, +) left = pd.Index(["1", "23", "456"]) # left operand @@ -67,7 +69,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives `npt.NDArray[np.int64]` in the static type # checking, where our `__radd__` cannot override. At runtime, they return # `Index`es. - check(assert_type(r0 + left, "npt.NDArray[np.str_]"), pd.Index, str) + check(assert_type(r0 + left, np_ndarray_str), pd.Index, str) else: # Python 3.10 uses NumPy 2.2.6, and it has for r0 ndarray[tuple[int,...], dtype[str_]] # Python 3.11+ uses NumPy 2.3.2, and it has for r0 ndarray[tuple[Any,...,dtype[str_]] diff --git a/tests/indexes/arithmetic/str/test_mul.py b/tests/indexes/arithmetic/str/test_mul.py index 5e50ef0f9..80852280a 100644 --- a/tests/indexes/arithmetic/str/test_mul.py +++ b/tests/indexes/arithmetic/str/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -98,13 +102,13 @@ def test_mul_numpy_array(left: "pd.Index[str]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Index` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: - assert_type(b * left, "npt.NDArray[np.bool_]") + assert_type(b * left, np_ndarray_bool) 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]") assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, np_ndarray_td) def test_mul_pd_index(left: "pd.Index[str]") -> None: diff --git a/tests/indexes/arithmetic/timedeltaindex/test_mul.py b/tests/indexes/arithmetic/timedeltaindex/test_mul.py index e4a9de79e..170a81b73 100644 --- a/tests/indexes/arithmetic/timedeltaindex/test_mul.py +++ b/tests/indexes/arithmetic/timedeltaindex/test_mul.py @@ -11,7 +11,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) @pytest.fixture @@ -78,7 +81,7 @@ def test_mul_numpy_array(left: pd.TimedeltaIndex) -> None: # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: # We made it Never, but numpy takes over - assert_type(b * left, "npt.NDArray[np.bool_]") + assert_type(b * left, np_ndarray_bool) check(assert_type(i * left, np_ndarray_int64), pd.TimedeltaIndex, pd.Timedelta) check( assert_type(f * left, "npt.NDArray[np.float64]"), diff --git a/tests/series/arithmetic/bool/test_add.py b/tests/series/arithmetic/bool/test_add.py index f27f7e599..c0ff5ac1b 100644 --- a/tests/series/arithmetic/bool/test_add.py +++ b/tests/series/arithmetic/bool/test_add.py @@ -4,7 +4,10 @@ from typing_extensions import assert_type from tests import check -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) left = pd.Series([True, True, False]) # left operand @@ -78,7 +81,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), pd.Series, np.bool_) 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( diff --git a/tests/series/arithmetic/bool/test_mul.py b/tests/series/arithmetic/bool/test_mul.py index 9b8ecc968..63402bf59 100644 --- a/tests/series/arithmetic/bool/test_mul.py +++ b/tests/series/arithmetic/bool/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -128,7 +132,7 @@ def test_mul_numpy_array(left: "pd.Series[bool]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), pd.Series, np.bool_) 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( @@ -138,7 +142,7 @@ def test_mul_numpy_array(left: "pd.Series[bool]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, np_ndarray_td) check(assert_type(left.mul(b), "pd.Series[bool]"), pd.Series, np.bool_) check(assert_type(left.mul(i), "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/series/arithmetic/complex/test_add.py b/tests/series/arithmetic/complex/test_add.py index 1b280d074..a6cddc424 100644 --- a/tests/series/arithmetic/complex/test_add.py +++ b/tests/series/arithmetic/complex/test_add.py @@ -4,7 +4,10 @@ from typing_extensions import assert_type from tests import check -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) left = pd.Series([1j, 2j, 3j]) # left operand @@ -90,7 +93,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), 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 82cea19af..dc955f641 100644 --- a/tests/series/arithmetic/complex/test_mul.py +++ b/tests/series/arithmetic/complex/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -140,7 +144,7 @@ def test_mul_numpy_array(left: "pd.Series[complex]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), 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 @@ -152,7 +156,7 @@ def test_mul_numpy_array(left: "pd.Series[complex]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, np_ndarray_td) check(assert_type(left.mul(b), "pd.Series[complex]"), pd.Series, np.complexfloating) check(assert_type(left.mul(i), "pd.Series[complex]"), pd.Series, np.complexfloating) diff --git a/tests/series/arithmetic/float/test_add.py b/tests/series/arithmetic/float/test_add.py index 161e72f44..ec61d805e 100644 --- a/tests/series/arithmetic/float/test_add.py +++ b/tests/series/arithmetic/float/test_add.py @@ -4,7 +4,10 @@ from typing_extensions import assert_type from tests import check -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) left = pd.Series([1.0, 2.0, 3.0]) # left operand @@ -78,7 +81,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), 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( diff --git a/tests/series/arithmetic/float/test_floordiv.py b/tests/series/arithmetic/float/test_floordiv.py index 1eeed3f75..436377adb 100644 --- a/tests/series/arithmetic/float/test_floordiv.py +++ b/tests/series/arithmetic/float/test_floordiv.py @@ -16,6 +16,9 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_int64, +) @pytest.fixture @@ -138,9 +141,7 @@ def test_floordiv_numpy_array(left: "pd.Series[float]") -> None: if TYPE_CHECKING_INVALID_USAGE: assert_type(c // left, Any) assert_type(s // left, Any) - check( - assert_type(d // left, "np.typing.NDArray[np.int64]"), pd.Series, pd.Timedelta - ) + check(assert_type(d // left, np_ndarray_int64), pd.Series, pd.Timedelta) check(assert_type(left.floordiv(b), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.floordiv(i), "pd.Series[float]"), pd.Series, np.floating) diff --git a/tests/series/arithmetic/float/test_mul.py b/tests/series/arithmetic/float/test_mul.py index 1248e7afe..8e56d10f5 100644 --- a/tests/series/arithmetic/float/test_mul.py +++ b/tests/series/arithmetic/float/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -128,7 +132,7 @@ def test_mul_numpy_array(left: "pd.Series[float]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), 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( @@ -138,7 +142,7 @@ def test_mul_numpy_array(left: "pd.Series[float]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - check(assert_type(d * left, "npt.NDArray[np.timedelta64]"), pd.Series, pd.Timedelta) + check(assert_type(d * left, np_ndarray_td), pd.Series, pd.Timedelta) check(assert_type(left.mul(b), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.mul(i), "pd.Series[float]"), pd.Series, np.floating) diff --git a/tests/series/arithmetic/int/test_add.py b/tests/series/arithmetic/int/test_add.py index 67e714b2d..45ef5469a 100644 --- a/tests/series/arithmetic/int/test_add.py +++ b/tests/series/arithmetic/int/test_add.py @@ -3,8 +3,13 @@ import pandas as pd from typing_extensions import assert_type -from tests import check -from tests._typing import np_ndarray_int64 +from tests import ( + check, +) +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) left = pd.Series([1, 2, 3]) # left operand @@ -78,7 +83,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b + left, np_ndarray_bool), 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( diff --git a/tests/series/arithmetic/int/test_floordiv.py b/tests/series/arithmetic/int/test_floordiv.py index 5b50316ff..9e4fc5542 100644 --- a/tests/series/arithmetic/int/test_floordiv.py +++ b/tests/series/arithmetic/int/test_floordiv.py @@ -5,6 +5,7 @@ from typing import Any import numpy as np +import numpy.typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -16,6 +17,9 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_int64, +) @pytest.fixture @@ -132,17 +136,13 @@ def test_floordiv_numpy_array(left: "pd.Series[int]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rfloordiv__` cannot override. At runtime, they lead to # errors or pd.Series. - check(assert_type(b // left, "np.typing.NDArray[np.int8]"), pd.Series, np.integer) - check(assert_type(i // left, "np.typing.NDArray[np.int64]"), pd.Series, np.integer) - check( - assert_type(f // left, "np.typing.NDArray[np.float64]"), pd.Series, np.floating - ) + check(assert_type(b // left, "npt.NDArray[np.int8]"), 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) if TYPE_CHECKING_INVALID_USAGE: assert_type(c // left, Any) assert_type(s // left, Any) - check( - assert_type(d // left, "np.typing.NDArray[np.int64]"), pd.Series, pd.Timedelta - ) + check(assert_type(d // left, np_ndarray_int64), pd.Series, pd.Timedelta) check(assert_type(left.floordiv(b), "pd.Series[int]"), pd.Series, np.integer) check(assert_type(left.floordiv(i), "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/series/arithmetic/int/test_mul.py b/tests/series/arithmetic/int/test_mul.py index 6957600f6..933412c7d 100644 --- a/tests/series/arithmetic/int/test_mul.py +++ b/tests/series/arithmetic/int/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -128,7 +132,7 @@ def test_mul_numpy_array(left: "pd.Series[int]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # 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(b * left, np_ndarray_bool), 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( @@ -138,7 +142,7 @@ def test_mul_numpy_array(left: "pd.Series[int]") -> None: ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - check(assert_type(d * left, "npt.NDArray[np.timedelta64]"), pd.Series, pd.Timedelta) + check(assert_type(d * left, np_ndarray_td), pd.Series, pd.Timedelta) check(assert_type(left.mul(b), "pd.Series[int]"), pd.Series, np.integer) check(assert_type(left.mul(i), "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/series/arithmetic/str/test_add.py b/tests/series/arithmetic/str/test_add.py index 498d93dc1..6aa5ce0ff 100644 --- a/tests/series/arithmetic/str/test_add.py +++ b/tests/series/arithmetic/str/test_add.py @@ -2,7 +2,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import ( Never, @@ -13,7 +12,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_int64, + np_ndarray_str, +) left = pd.Series(["1", "23", "456"]) # left operand @@ -85,7 +87,7 @@ def test_add_numpy_array() -> None: # `numpy` typing gives `npt.NDArray[np.int64]` in the static type # checking, where our `__radd__` cannot override. At runtime, they return # `Series`. - check(assert_type(r0 + left, "npt.NDArray[np.str_]"), pd.Series, str) + check(assert_type(r0 + left, np_ndarray_str), pd.Series, str) else: # Python 3.10 uses NumPy 2.2.6, and it has for r0 ndarray[tuple[int,...], dtype[str_]] # Python 3.11+ uses NumPy 2.3.2, and it has for r0 ndarray[tuple[Any,...,dtype[str_]] diff --git a/tests/series/arithmetic/str/test_mul.py b/tests/series/arithmetic/str/test_mul.py index 743de8e49..ab27a7858 100644 --- a/tests/series/arithmetic/str/test_mul.py +++ b/tests/series/arithmetic/str/test_mul.py @@ -17,7 +17,11 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, + np_ndarray_td, +) @pytest.fixture @@ -134,13 +138,13 @@ def test_mul_numpy_array(left: "pd.Series[str]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: - assert_type(b * left, "npt.NDArray[np.bool_]") + assert_type(b * left, np_ndarray_bool) 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]") assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, np_ndarray_td) if TYPE_CHECKING_INVALID_USAGE: left.mul(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] diff --git a/tests/series/arithmetic/test_sub.py b/tests/series/arithmetic/test_sub.py index 21398e881..267e380d8 100644 --- a/tests/series/arithmetic/test_sub.py +++ b/tests/series/arithmetic/test_sub.py @@ -233,7 +233,7 @@ def test_sub_ts_numpy_datetime() -> None: check(assert_type(left_ts - s, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) check(assert_type(left_ts - a, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) - # Series[Any] (Timedelta) - np.datetime64 or np.typing.NDArray[np.datetime64] + # Series[Any] (Timedelta) - np.datetime64 or npt.NDArray[np.datetime64] # fails at runtime, # which cannot be revealed by our static type checking # left_td - s @@ -262,7 +262,7 @@ def test_sub_ts_numpy_datetime() -> None: check( assert_type(left_ts.sub(a), "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta ) - # Series[Any] (Timedelta).sub(np.datetime64 or np.typing.NDArray[np.datetime64]) + # Series[Any] (Timedelta).sub(np.datetime64 or npt.NDArray[np.datetime64]) # fails at runtime, # which cannot be revealed by our static type checking # left_td.sub(s) diff --git a/tests/series/arithmetic/timedelta/test_add.py b/tests/series/arithmetic/timedelta/test_add.py index 4aee2bd02..6409ffe1d 100644 --- a/tests/series/arithmetic/timedelta/test_add.py +++ b/tests/series/arithmetic/timedelta/test_add.py @@ -4,7 +4,6 @@ ) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -12,6 +11,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_dt, + np_ndarray_td, +) left = pd.Series([pd.Timedelta(1, "s")]) # left operand @@ -102,8 +105,8 @@ def test_add_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__radd__` cannot override. At runtime, they return # `Series`. - check(assert_type(s + left, "npt.NDArray[np.datetime64]"), pd.Series, pd.Timestamp) - check(assert_type(d + left, "npt.NDArray[np.timedelta64]"), pd.Series, pd.Timedelta) + check(assert_type(s + left, np_ndarray_dt), pd.Series, pd.Timestamp) + check(assert_type(d + left, np_ndarray_td), pd.Series, pd.Timedelta) check(assert_type(left.add(s), "pd.Series[pd.Timestamp]"), pd.Series, pd.Timestamp) check(assert_type(left.add(d), "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) diff --git a/tests/series/arithmetic/timedelta/test_mul.py b/tests/series/arithmetic/timedelta/test_mul.py index ebd29f4d7..2f5f5db18 100644 --- a/tests/series/arithmetic/timedelta/test_mul.py +++ b/tests/series/arithmetic/timedelta/test_mul.py @@ -11,7 +11,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) -from tests._typing import np_ndarray_int64 +from tests._typing import ( + np_ndarray_bool, + np_ndarray_int64, +) @pytest.fixture @@ -105,7 +108,7 @@ def test_mul_numpy_array(left: "pd.Series[pd.Timedelta]") -> None: # checking, where our `__rmul__` cannot override. At runtime, they return # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: - assert_type(b * left, "npt.NDArray[np.bool_]") + assert_type(b * left, np_ndarray_bool) 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: diff --git a/tests/series/arithmetic/timedelta/test_sub.py b/tests/series/arithmetic/timedelta/test_sub.py index c50abed21..c4c618b25 100644 --- a/tests/series/arithmetic/timedelta/test_sub.py +++ b/tests/series/arithmetic/timedelta/test_sub.py @@ -4,7 +4,6 @@ ) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import ( Never, @@ -15,6 +14,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_dt, + np_ndarray_td, +) left = pd.Series([pd.Timedelta(1, "s")]) # left operand @@ -112,8 +115,8 @@ def test_sub_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rsub__` cannot override. At runtime, they return # `Series`. - check(assert_type(s - left, "npt.NDArray[np.datetime64]"), pd.Series, pd.Timestamp) - check(assert_type(d - left, "npt.NDArray[np.timedelta64]"), pd.Series, pd.Timedelta) + check(assert_type(s - left, np_ndarray_dt), pd.Series, pd.Timestamp) + check(assert_type(d - left, np_ndarray_td), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: left.sub(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] diff --git a/tests/series/arithmetic/timestamp/test_add.py b/tests/series/arithmetic/timestamp/test_add.py index 03cde2db0..03029e7d8 100644 --- a/tests/series/arithmetic/timestamp/test_add.py +++ b/tests/series/arithmetic/timestamp/test_add.py @@ -4,7 +4,6 @@ ) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import ( Never, @@ -15,6 +14,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_dt, + np_ndarray_td, +) left = pd.Series([pd.Timestamp(2025, 8, 20)]) # left operand @@ -120,10 +123,10 @@ def test_add_numpy_array() -> None: # checking, where our `__radd__` cannot override. At runtime, they return # `Series`. if TYPE_CHECKING_INVALID_USAGE: - assert_type(s + left, "npt.NDArray[np.datetime64]") + assert_type(s + left, np_ndarray_dt) # Here even the dtype of `NDArray` is in the wrong direction. # `np.datetime64` would be more sensible. - check(assert_type(d + left, "npt.NDArray[np.timedelta64]"), pd.Series, pd.Timestamp) + check(assert_type(d + left, np_ndarray_td), pd.Series, pd.Timestamp) if TYPE_CHECKING_INVALID_USAGE: left.add(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] diff --git a/tests/series/arithmetic/timestamp/test_sub.py b/tests/series/arithmetic/timestamp/test_sub.py index c680e30eb..b5ae269f9 100644 --- a/tests/series/arithmetic/timestamp/test_sub.py +++ b/tests/series/arithmetic/timestamp/test_sub.py @@ -4,7 +4,6 @@ ) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -12,6 +11,10 @@ TYPE_CHECKING_INVALID_USAGE, check, ) +from tests._typing import ( + np_ndarray_dt, + np_ndarray_td, +) left = pd.Series([pd.Timestamp(2025, 8, 20)]) # left operand @@ -109,9 +112,9 @@ def test_sub_numpy_array() -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rsub__` cannot override. At runtime, they return # `Series`. - check(assert_type(s - left, "npt.NDArray[np.datetime64]"), pd.Series, pd.Timedelta) + check(assert_type(s - left, np_ndarray_dt), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: - assert_type(d - left, "npt.NDArray[np.timedelta64]") + assert_type(d - left, np_ndarray_td) check(assert_type(left.sub(s), "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) check(assert_type(left - d, "pd.Series[pd.Timestamp]"), pd.Series, pd.Timestamp)