From 2af001ae028b6f0c4cc652b7154a5f16feca1154 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sat, 1 Nov 2025 12:37:56 +0100 Subject: [PATCH 01/11] simplify missing --- pandas-stubs/_libs/missing.pyi | 221 ++++++++++++++------------------- 1 file changed, 91 insertions(+), 130 deletions(-) diff --git a/pandas-stubs/_libs/missing.pyi b/pandas-stubs/_libs/missing.pyi index f0bf682e3..cba9dc583 100644 --- a/pandas-stubs/_libs/missing.pyi +++ b/pandas-stubs/_libs/missing.pyi @@ -5,236 +5,197 @@ from typing import ( overload, ) -from pandas import ( - Index, - Series, -) +import numpy as np from pandas.core.arrays.boolean import BooleanArray +from pandas.core.indexes.base import Index +from pandas.core.series import Series from typing_extensions import Self +from pandas._typing import Scalar + class NAType: def __new__(cls, *args: Any, **kwargs: Any) -> Self: ... def __format__(self, format_spec: str) -> str: ... def __hash__(self) -> int: ... def __reduce__(self) -> str: ... @overload - def __add__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __add__(self, other: Series, /) -> Series: ... @overload - def __add__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __add__(self, other: Index, /) -> Index: ... @overload - def __add__(self, other: object, /) -> NAType: ... + def __add__(self, other: Scalar, /) -> NAType: ... @overload - def __radd__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __radd__(self, other: Series, /) -> Series: ... @overload - def __radd__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __radd__(self, other: Index, /) -> Index: ... @overload - def __radd__(self, other: object, /) -> NAType: ... + def __radd__(self, other: Scalar, /) -> NAType: ... @overload - def __sub__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __sub__(self, other: Series, /) -> Series: ... @overload - def __sub__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __sub__(self, other: Index, /) -> Index: ... @overload - def __sub__(self, other: object, /) -> NAType: ... + def __sub__(self, other: Scalar, /) -> NAType: ... @overload - def __rsub__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rsub__(self, other: Series, /) -> Series: ... @overload - def __rsub__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rsub__(self, other: Index, /) -> Index: ... @overload - def __rsub__(self, other: object, /) -> NAType: ... + def __rsub__(self, other: Scalar, /) -> NAType: ... @overload - def __mul__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __mul__(self, other: Series, /) -> Series: ... @overload - def __mul__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __mul__(self, other: Index, /) -> Index: ... @overload - def __mul__(self, other: object, /) -> NAType: ... + def __mul__(self, other: Scalar, /) -> NAType: ... @overload - def __rmul__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rmul__(self, other: Series, /) -> Series: ... @overload - def __rmul__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rmul__(self, other: Index, /) -> Index: ... @overload - def __rmul__(self, other: object, /) -> NAType: ... - def __matmul__(self, other: object, /) -> NAType: ... - def __rmatmul__(self, other: object, /) -> NAType: ... + def __rmul__(self, other: Scalar, /) -> NAType: ... + def __matmul__(self, other: Scalar, /) -> NAType: ... + def __rmatmul__(self, other: Scalar, /) -> NAType: ... @overload - def __truediv__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __truediv__(self, other: Series, /) -> Series: ... @overload - def __truediv__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __truediv__(self, other: Index, /) -> Index: ... @overload - def __truediv__(self, other: object, /) -> NAType: ... + def __truediv__(self, other: Scalar, /) -> NAType: ... @overload - def __rtruediv__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rtruediv__(self, other: Series, /) -> Series: ... @overload - def __rtruediv__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rtruediv__(self, other: Index, /) -> Index: ... @overload - def __rtruediv__(self, other: object, /) -> NAType: ... + def __rtruediv__(self, other: Scalar, /) -> NAType: ... @overload - def __floordiv__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __floordiv__(self, other: Series, /) -> Series: ... @overload - def __floordiv__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __floordiv__(self, other: Index, /) -> Index: ... @overload - def __floordiv__(self, other: object, /) -> NAType: ... + def __floordiv__(self, other: Scalar, /) -> NAType: ... @overload - def __rfloordiv__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rfloordiv__(self, other: Series, /) -> Series: ... @overload - def __rfloordiv__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rfloordiv__(self, other: Index, /) -> Index: ... @overload - def __rfloordiv__(self, other: object, /) -> NAType: ... + def __rfloordiv__(self, other: Scalar, /) -> NAType: ... @overload - def __mod__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __mod__(self, other: Series, /) -> Series: ... @overload - def __mod__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __mod__(self, other: Index, /) -> Index: ... @overload - def __mod__(self, other: object, /) -> NAType: ... + def __mod__(self, other: Scalar, /) -> NAType: ... @overload - def __rmod__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rmod__(self, other: Series, /) -> Series: ... @overload - def __rmod__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rmod__(self, other: Index, /) -> Index: ... @overload - def __rmod__(self, other: object, /) -> NAType: ... + def __rmod__(self, other: Scalar, /) -> NAType: ... @overload - def __divmod__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> tuple[Series, Series]: ... + def __divmod__(self, other: Series, /) -> tuple[Series, Series]: ... @overload - def __divmod__(self, other: Index, /) -> tuple[Index, Index]: ... # type: ignore[overload-overlap] + def __divmod__(self, other: Index, /) -> tuple[Index, Index]: ... @overload - def __divmod__(self, other: object, /) -> tuple[NAType, NAType]: ... + def __divmod__(self, other: Scalar, /) -> tuple[NAType, NAType]: ... @overload - def __rdivmod__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> tuple[Series, Series]: ... + def __rdivmod__(self, other: Series, /) -> tuple[Series, Series]: ... @overload - def __rdivmod__(self, other: Index, /) -> tuple[Index, Index]: ... # type: ignore[overload-overlap] + def __rdivmod__(self, other: Index, /) -> tuple[Index, Index]: ... @overload - def __rdivmod__(self, other: object, /) -> tuple[NAType, NAType]: ... + def __rdivmod__(self, other: Scalar, /) -> tuple[NAType, NAType]: ... @overload # type: ignore[override] - def __eq__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series[bool]: ... + def __eq__(self, other: Series, /) -> Series[bool]: ... @overload - def __eq__(self, other: Index, /) -> BooleanArray: ... # type: ignore[overload-overlap] + def __eq__(self, other: Index, /) -> BooleanArray: ... @overload def __eq__( # pyright: ignore[reportIncompatibleMethodOverride] - self, other: object, / + self, other: Scalar, / ) -> NAType: ... @overload # type: ignore[override] - def __ne__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series[bool]: ... + def __ne__(self, other: Series, /) -> Series[bool]: ... @overload - def __ne__(self, other: Index, /) -> BooleanArray: ... # type: ignore[overload-overlap] + def __ne__(self, other: Index, /) -> BooleanArray: ... @overload def __ne__( # pyright: ignore[reportIncompatibleMethodOverride] - self, other: object, / + self, other: Scalar, / ) -> NAType: ... @overload - def __le__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series[bool]: ... + def __le__(self, other: Series, /) -> Series[bool]: ... @overload - def __le__(self, other: Index, /) -> BooleanArray: ... # type: ignore[overload-overlap] + def __le__(self, other: Index, /) -> BooleanArray: ... @overload - def __le__(self, other: object, /) -> NAType: ... + def __le__(self, other: Scalar, /) -> NAType: ... @overload - def __lt__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series[bool]: ... + def __lt__(self, other: Series, /) -> Series[bool]: ... @overload - def __lt__(self, other: Index, /) -> BooleanArray: ... # type: ignore[overload-overlap] + def __lt__(self, other: Index, /) -> BooleanArray: ... @overload - def __lt__(self, other: object, /) -> NAType: ... + def __lt__(self, other: Scalar, /) -> NAType: ... @overload - def __gt__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series[bool]: ... + def __gt__(self, other: Series, /) -> Series[bool]: ... @overload - def __gt__(self, other: Index, /) -> BooleanArray: ... # type: ignore[overload-overlap] + def __gt__(self, other: Index, /) -> BooleanArray: ... @overload - def __gt__(self, other: object, /) -> NAType: ... + def __gt__(self, other: Scalar, /) -> NAType: ... @overload - def __ge__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series[bool]: ... + def __ge__(self, other: Series, /) -> Series[bool]: ... @overload - def __ge__(self, other: Index, /) -> BooleanArray: ... # type: ignore[overload-overlap] + def __ge__(self, other: Index, /) -> BooleanArray: ... @overload - def __ge__(self, other: object, /) -> NAType: ... + def __ge__(self, other: Scalar, /) -> NAType: ... def __neg__(self) -> NAType: ... def __pos__(self) -> NAType: ... def __abs__(self) -> NAType: ... def __invert__(self) -> NAType: ... @overload - def __pow__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __pow__(self, other: Series, /) -> Series: ... @overload - def __pow__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __pow__(self, other: Index, /) -> Index: ... @overload - def __pow__(self, other: object, /) -> NAType: ... + def __pow__(self, other: complex, /) -> NAType: ... @overload - def __rpow__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rpow__(self, other: Series, /) -> Series: ... @overload - def __rpow__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rpow__(self, other: Index, /) -> Index: ... @overload - def __rpow__(self, other: object, /) -> NAType: ... + def __rpow__(self, other: complex, /) -> NAType: ... @overload - def __and__(self, other: Literal[False], /) -> Literal[False]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + def __and__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + self, other: Literal[False], / + ) -> Literal[False]: ... @overload def __and__(self, other: bool | NAType, /) -> NAType: ... @overload - def __rand__(self, other: Literal[False], /) -> Literal[False]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + def __rand__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + self, other: Literal[False], / + ) -> Literal[False]: ... @overload def __rand__(self, other: bool, /) -> NAType: ... @overload - def __or__(self, other: Literal[True], /) -> Literal[True]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + def __or__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + self, other: Literal[True], / + ) -> Literal[True]: ... @overload def __or__(self, other: bool | NAType, /) -> NAType: ... @overload - def __ror__(self, other: Literal[True], /) -> Literal[True]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + def __ror__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + self, other: Literal[True], / + ) -> Literal[True]: ... @overload def __ror__(self, other: bool | NAType, /) -> NAType: ... @overload - def __xor__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __xor__(self, other: Series, /) -> Series: ... @overload - def __xor__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __xor__(self, other: Index, /) -> Index: ... @overload - def __xor__(self, other: object, /) -> NAType: ... + def __xor__(self, other: bool | np.bool, /) -> NAType: ... @overload - def __rxor__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] - self, other: Series, / - ) -> Series: ... + def __rxor__(self, other: Series, /) -> Series: ... @overload - def __rxor__(self, other: Index, /) -> Index: ... # type: ignore[overload-overlap] + def __rxor__(self, other: Index, /) -> Index: ... @overload - def __rxor__(self, other: object, /) -> NAType: ... + def __rxor__(self, other: bool | np.bool, /) -> NAType: ... __array_priority__: int def __array_ufunc__( self, ufunc: Callable[..., Any], method: str, *inputs: Any, **kwargs: Any From 51b85f8d2303e7867983e8fe236603c3b2de1fac Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 00:28:54 +0100 Subject: [PATCH 02/11] resolve unique --- pandas-stubs/_typing.pyi | 2 ++ pandas-stubs/core/algorithms.pyi | 29 ++++++++++---------- pandas-stubs/core/base.pyi | 3 ++- pandas-stubs/core/indexes/base.pyi | 22 ++++++++------- pandas-stubs/core/indexes/category.pyi | 11 +++++--- pandas-stubs/core/indexes/datetimelike.pyi | 5 ++-- pandas-stubs/core/indexes/datetimes.pyi | 3 ++- pandas-stubs/core/indexes/extension.pyi | 3 ++- pandas-stubs/core/indexes/interval.pyi | 6 +++-- pandas-stubs/core/indexes/period.pyi | 4 ++- pandas-stubs/core/indexes/range.pyi | 2 +- pandas-stubs/core/indexes/timedeltas.pyi | 3 ++- pandas-stubs/core/series.pyi | 19 ++++++------- tests/series/test_series.py | 5 +--- tests/test_pandas.py | 31 +++++++++++++--------- 15 files changed, 85 insertions(+), 63 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 5f0277185..bbaca8987 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -938,6 +938,8 @@ C2 = TypeVar( BaseOffset, ) +A1_co = TypeVar("A1_co", default=Any, covariant=True) + IndexingInt: TypeAlias = ( int | np.int_ | np.integer | np.unsignedinteger | np.signedinteger | np.int8 ) diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index 5174218c6..441831161 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -5,18 +5,19 @@ from typing import ( ) import numpy as np -from pandas import ( - Categorical, - CategoricalIndex, - Index, - IntervalIndex, - PeriodIndex, - Series, -) +from numpy import typing as npt from pandas.api.extensions import ExtensionArray +from pandas.core.arrays.categorical import Categorical +from pandas.core.indexes.base import Index +from pandas.core.indexes.category import CategoricalIndex +from pandas.core.indexes.interval import IntervalIndex +from pandas.core.indexes.period import PeriodIndex +from pandas.core.series import Series from pandas._typing import ( + S1, AnyArrayLike, + GenericT_co, IntervalT, TakeIndexer, np_1darray, @@ -26,21 +27,21 @@ from pandas._typing import ( # with extension types return the same type while standard type return ndarray @overload -def unique( # pyright: ignore[reportOverlappingOverload] - values: PeriodIndex, -) -> PeriodIndex: ... +def unique(values: PeriodIndex) -> PeriodIndex: ... @overload -def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[overload-overlap] +def unique( + values: CategoricalIndex[S1, GenericT_co], +) -> CategoricalIndex[S1, GenericT_co]: ... @overload def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... @overload -def unique(values: Index) -> np.ndarray: ... +def unique(values: Index[S1, np_1darray, GenericT_co]) -> np_1darray[GenericT_co]: ... @overload def unique(values: Categorical) -> Categorical: ... @overload def unique(values: Series) -> np.ndarray | ExtensionArray: ... @overload -def unique(values: np.ndarray) -> np.ndarray: ... +def unique(values: npt.NDArray[GenericT_co]) -> np_1darray[GenericT_co]: ... @overload def unique(values: ExtensionArray) -> ExtensionArray: ... @overload diff --git a/pandas-stubs/core/base.pyi b/pandas-stubs/core/base.pyi index ea3865add..96ed0c28a 100644 --- a/pandas-stubs/core/base.pyi +++ b/pandas-stubs/core/base.pyi @@ -29,6 +29,7 @@ from pandas._libs.tslibs.timedeltas import Timedelta from pandas._typing import ( S1, S2, + A1_co, AxisIndex, DropKeep, DTypeLike, @@ -59,7 +60,7 @@ class SelectionMixin(Generic[NDFrameT]): def __getitem__(self, key): ... def aggregate(self, func, *args: Any, **kwargs: Any): ... -class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]): +class IndexOpsMixin(OpsMixin, Generic[S1, A1_co, GenericT_co]): __array_priority__: int = ... @property def T(self) -> Self: ... diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi index 21aa39db3..ed0bdd95d 100644 --- a/pandas-stubs/core/indexes/base.pyi +++ b/pandas-stubs/core/indexes/base.pyi @@ -14,7 +14,6 @@ from pathlib import Path from typing import ( Any, ClassVar, - Generic, Literal, final, overload, @@ -67,6 +66,7 @@ from pandas._typing import ( S2, S2_NSDT, T_COMPLEX, + A1_co, AnyAll, AnyArrayLike, AnyArrayLikeInt, @@ -109,7 +109,7 @@ from pandas._typing import ( class InvalidIndexError(Exception): ... -class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): +class Index(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1]): __hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride] # overloads with additional dtypes @overload @@ -475,15 +475,19 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): @overload def where( self, - cond: Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool], - other: S1 | Series[S1] | Self, + cond: ( + Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool, A1_co] + ), + other: S1 | Series[S1, A1_co] | Self, ) -> Self: ... @overload def where( self, - cond: Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool], + cond: ( + Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool, A1_co] + ), other: Scalar | AnyArrayLike | None = None, - ) -> Index: ... + ) -> Index[Any, A1_co]: ... def __contains__(self, key: Hashable) -> bool: ... @final def __setitem__(self, key, value) -> None: ... @@ -541,7 +545,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): @overload def insert(self, loc: int, item: S1) -> Self: ... @overload - def insert(self, loc: int, item: object) -> Index: ... + def insert(self, loc: int, item: Any) -> Index[Any, A1_co]: ... def drop(self, labels, errors: IgnoreRaise = "raise") -> Self: ... @property def shape(self) -> tuple[int, ...]: ... @@ -731,7 +735,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): ), ) -> Index[complex]: ... @overload - def __rsub__(self: Index[Never], other: DatetimeIndex) -> Never: ... # type: ignore[misc] + def __rsub__(self: Index[Never], other: DatetimeIndex) -> Never: ... @overload def __rsub__( self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index @@ -1051,7 +1055,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): def infer_objects(self, copy: bool = True) -> Self: ... @type_check_only -class _IndexSubclassBase(Index[S1], Generic[S1, GenericT_co]): +class _IndexSubclassBase(Index[S1, A1_co, GenericT_co]): @overload def to_numpy( self, diff --git a/pandas-stubs/core/indexes/category.pyi b/pandas-stubs/core/indexes/category.pyi index 92c60cff9..a72040a93 100644 --- a/pandas-stubs/core/indexes/category.pyi +++ b/pandas-stubs/core/indexes/category.pyi @@ -3,7 +3,6 @@ from collections.abc import ( Iterable, ) -import numpy as np from pandas.core import accessor from pandas.core.arrays.categorical import Categorical from pandas.core.indexes.base import Index @@ -13,12 +12,16 @@ from typing_extensions import Self from pandas._typing import ( S1, Dtype, + GenericT_co, ListLike, + np_1darray, ) -class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate): - codes: np.ndarray = ... - categories: Index = ... +class CategoricalIndex( + ExtensionIndex[S1, Categorical, GenericT_co], accessor.PandasDelegate +): + codes: np_1darray[GenericT_co] = ... + categories: Index[S1] = ... @property def array(self) -> Categorical: ... # type: ignore[override] # pyrefly: ignore[bad-override] def __new__( diff --git a/pandas-stubs/core/indexes/datetimelike.pyi b/pandas-stubs/core/indexes/datetimelike.pyi index 32739270e..0ae5faf3f 100644 --- a/pandas-stubs/core/indexes/datetimelike.pyi +++ b/pandas-stubs/core/indexes/datetimelike.pyi @@ -10,13 +10,14 @@ from typing_extensions import ( from pandas._libs.tslibs import BaseOffset from pandas._typing import ( S1, + A1_co, AxisIndex, GenericT_co, TimeUnit, np_ndarray_complex, ) -class DatetimeIndexOpsMixin(ExtensionIndex[S1, GenericT_co]): +class DatetimeIndexOpsMixin(ExtensionIndex[S1, A1_co, GenericT_co]): @property def freq(self) -> BaseOffset | None: ... @property @@ -58,7 +59,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1, GenericT_co]): self, other: np_ndarray_complex ) -> Never: ... -class DatetimeTimedeltaMixin(DatetimeIndexOpsMixin[S1, GenericT_co]): +class DatetimeTimedeltaMixin(DatetimeIndexOpsMixin[S1, A1_co, GenericT_co]): @property def unit(self) -> TimeUnit: ... def as_unit(self, unit: TimeUnit) -> Self: ... diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 58166f29f..033d7fa31 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -26,6 +26,7 @@ from pandas.core.series import Series from typing_extensions import Self from pandas._typing import ( + A1_co, AxesData, DateAndDatetimeLike, Dtype, @@ -43,7 +44,7 @@ from pandas.core.dtypes.dtypes import DatetimeTZDtype from pandas.tseries.offsets import BaseOffset class DatetimeIndex( - DatetimeTimedeltaMixin[Timestamp, np.datetime64], DatetimeIndexProperties + DatetimeTimedeltaMixin[Timestamp, A1_co, np.datetime64], DatetimeIndexProperties ): def __new__( cls, diff --git a/pandas-stubs/core/indexes/extension.pyi b/pandas-stubs/core/indexes/extension.pyi index 418816d8d..ac450a8d9 100644 --- a/pandas-stubs/core/indexes/extension.pyi +++ b/pandas-stubs/core/indexes/extension.pyi @@ -2,7 +2,8 @@ from pandas.core.indexes.base import _IndexSubclassBase from pandas._typing import ( S1, + A1_co, GenericT_co, ) -class ExtensionIndex(_IndexSubclassBase[S1, GenericT_co]): ... +class ExtensionIndex(_IndexSubclassBase[S1, A1_co, GenericT_co]): ... diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index 11f8227a1..48f33b622 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -11,7 +11,7 @@ from typing import ( import numpy as np import pandas as pd -from pandas import Index +from pandas.core.indexes.base import Index from pandas.core.indexes.extension import ExtensionIndex from pandas._libs.interval import ( @@ -60,7 +60,9 @@ _EdgesTimedelta: TypeAlias = ( _TimestampLike: TypeAlias = pd.Timestamp | np.datetime64 | dt.datetime _TimedeltaLike: TypeAlias = pd.Timedelta | np.timedelta64 | dt.timedelta -class IntervalIndex(ExtensionIndex[IntervalT, np.object_], IntervalMixin): +class IntervalIndex( + ExtensionIndex[IntervalT, IntervalIndex, np.object_], IntervalMixin +): closed: IntervalClosedType def __new__( diff --git a/pandas-stubs/core/indexes/period.pyi b/pandas-stubs/core/indexes/period.pyi index 84abc62ea..78b545539 100644 --- a/pandas-stubs/core/indexes/period.pyi +++ b/pandas-stubs/core/indexes/period.pyi @@ -25,7 +25,9 @@ from pandas._typing import ( np_1darray, ) -class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexFieldOps): +class PeriodIndex( + DatetimeIndexOpsMixin[pd.Period, np_1darray, np.object_], PeriodIndexFieldOps +): def __new__( cls, data: AxesData[Any] | None = None, diff --git a/pandas-stubs/core/indexes/range.pyi b/pandas-stubs/core/indexes/range.pyi index 8194dac79..5deea210d 100644 --- a/pandas-stubs/core/indexes/range.pyi +++ b/pandas-stubs/core/indexes/range.pyi @@ -28,7 +28,7 @@ from pandas._typing import ( np_ndarray_bool, ) -class RangeIndex(_IndexSubclassBase[int, np.int64]): +class RangeIndex(_IndexSubclassBase[int, np.ndarray, np.int64]): def __new__( cls, start: int | RangeIndex | range | None = None, diff --git a/pandas-stubs/core/indexes/timedeltas.pyi b/pandas-stubs/core/indexes/timedeltas.pyi index dd1a8b189..763eeb3b0 100644 --- a/pandas-stubs/core/indexes/timedeltas.pyi +++ b/pandas-stubs/core/indexes/timedeltas.pyi @@ -26,6 +26,7 @@ from pandas._libs import Timedelta from pandas._libs.tslibs import BaseOffset from pandas._libs.tslibs.period import Period from pandas._typing import ( + A1_co, AxesData, Frequency, Just, @@ -52,7 +53,7 @@ _DT_FACTOR: TypeAlias = dt.timedelta | np.timedelta64 | Timedelta _DT_FACTOR_SEQ: TypeAlias = _DT_FACTOR | Sequence[_DT_FACTOR] | np_ndarray_td class TimedeltaIndex( - DatetimeTimedeltaMixin[Timedelta, np.timedelta64], TimedeltaIndexProperties + DatetimeTimedeltaMixin[Timedelta, A1_co, np.timedelta64], TimedeltaIndexProperties ): def __new__( cls, diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 32b6bc8a5..3394b3203 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -122,6 +122,7 @@ from pandas._typing import ( S2, S2_NSDT, T_COMPLEX, + A1_co, AggFuncTypeBase, AggFuncTypeDictFrame, AggFuncTypeSeriesToFrame, @@ -310,7 +311,7 @@ _DataLikeS1: TypeAlias = ( ArrayLike | dict[_str, np.ndarray] | Sequence[S1] | IndexOpsMixin[S1] ) -class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): +class Series(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1], NDFrame): # Define __index__ because mypy thinks Series follows protocol `SupportsIndex` https://github.com/pandas-dev/pandas-stubs/pull/1332#discussion_r2285648790 __index__: ClassVar[None] __hash__: ClassVar[None] # pyright: ignore[reportIncompatibleMethodOverride] @@ -860,7 +861,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): def count(self) -> int: ... def mode(self, dropna: bool = True) -> Series[S1]: ... @overload - def unique(self: Series[Never]) -> np.ndarray: ... # type: ignore[overload-overlap] + def unique(self: Series[Never]) -> np.ndarray: ... @overload def unique(self: Series[Timestamp]) -> DatetimeArray: ... # type: ignore[overload-overlap] @overload @@ -882,7 +883,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): keep: DropKeep = ..., inplace: Literal[False] = False, ignore_index: _bool = ..., - ) -> Series[S1]: ... + ) -> Self: ... def duplicated(self, keep: DropKeep = "first") -> Series[_bool]: ... def idxmax( self, @@ -898,7 +899,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): *args: Any, **kwargs: Any, ) -> int | _str: ... - def round(self, decimals: int = 0, *args: Any, **kwargs: Any) -> Series[S1]: ... + def round(self, decimals: int = 0, *args: Any, **kwargs: Any) -> Self: ... @overload def quantile( self, @@ -921,7 +922,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): self, other: Series[S1], min_periods: int | None = None, ddof: int = 1 ) -> float: ... @overload - def diff( # type: ignore[overload-overlap] + def diff( self: Series[Never] | Series[int], periods: int = ... ) -> Series[float]: ... @overload @@ -2524,7 +2525,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): self, other: S1 | ListLike | Series[S1] | datetime | timedelta | date ) -> Series[_bool]: ... @overload - def __mul__( # type: ignore[overload-overlap] + def __mul__( self: Series[Never], other: complex | NumListLike | Index | Series ) -> Series: ... @overload @@ -2740,7 +2741,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): axis: int = 0, ) -> Series[complex]: ... @overload - def __rmul__( # type: ignore[overload-overlap] + def __rmul__( self: Series[Never], other: complex | NumListLike | Index | Series ) -> Series: ... @overload @@ -2748,7 +2749,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): @overload def __rmul__(self, other: np_ndarray_dt) -> Never: ... @overload - def __rmul__( # type: ignore[overload-overlap] + def __rmul__( self: Series[int] | Series[float], other: ( timedelta @@ -3880,7 +3881,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): ) -> Series: ... div = truediv @overload - def __rtruediv__( # type: ignore[overload-overlap] + def __rtruediv__( self: Series[Never], other: complex | NumListLike | Index | Series ) -> Series: ... @overload diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 73bc51bb5..15032eaf8 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -1192,10 +1192,7 @@ def test_types_groupby_iter() -> None: s = pd.Series([1, 1, 2], dtype=int) series_groupby = pd.Series([True, True, False], dtype=bool) first_group = next(iter(s.groupby(series_groupby))) - check( - assert_type(first_group[0], bool), - bool, - ) + check(assert_type(first_group[0], bool), bool) check(assert_type(first_group[1], "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 6925582ac..56d2c5c4b 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -609,12 +609,12 @@ def test_unique() -> None: ] ) ), - np.ndarray, + np_1darray[np.datetime64], ), pd.DatetimeIndex, ) - check(assert_type(pd.unique(np.array(list("baabc"))), np.ndarray), np.ndarray) + check(assert_type(pd.unique(np.array(list("baabc"))), np_1darray), np.ndarray) check( assert_type( @@ -642,12 +642,12 @@ def test_unique() -> None: pd.Categorical, ) check( - assert_type(pd.unique(pd.Index(["a", "b", "c", "a"])), np.ndarray), + assert_type(pd.unique(pd.Index(["a", "b", "c", "a"])), np_1darray), np.ndarray if PD_LTE_23 else pd.Index, ) check( - assert_type(pd.unique(pd.RangeIndex(0, 10)), np.ndarray), - np.ndarray if PD_LTE_23 else pd.Index, + assert_type(pd.unique(pd.RangeIndex(0, 10)), np_1darray[np.int64]), + np_1darray if PD_LTE_23 else pd.Index, ) check( assert_type(pd.unique(pd.Categorical(["a", "b", "c", "a"])), pd.Categorical), @@ -663,9 +663,9 @@ def test_unique() -> None: check( assert_type( pd.unique(pd.timedelta_range(start="1 day", periods=4)), - np.ndarray, + np_1darray[np.timedelta64], ), - np.ndarray if PD_LTE_23 else pd.Index, + np_1darray[np.timedelta64] if PD_LTE_23 else pd.Index, ) @@ -984,17 +984,22 @@ def test_index_unqiue() -> None: mi = pd.MultiIndex.from_product([["a", "b"], ["apple", "banana"]]) interval_i = pd.interval_range(1, 10, periods=10) - check(assert_type(pd.unique(ci), pd.CategoricalIndex), pd.CategoricalIndex) + check(assert_type(pd.unique(ci), pd.CategoricalIndex[str]), pd.CategoricalIndex) check( - assert_type(pd.unique(dti), np.ndarray), np.ndarray if PD_LTE_23 else pd.Index + assert_type(pd.unique(dti), np_1darray[np.datetime64]), + np.ndarray if PD_LTE_23 else pd.Index, ) - check(assert_type(pd.unique(i), np.ndarray), np.ndarray if PD_LTE_23 else pd.Index) + check(assert_type(pd.unique(i), np_1darray), np.ndarray if PD_LTE_23 else pd.Index) check(assert_type(pd.unique(pi), pd.PeriodIndex), pd.PeriodIndex) - check(assert_type(pd.unique(ri), np.ndarray), np.ndarray if PD_LTE_23 else pd.Index) check( - assert_type(pd.unique(tdi), np.ndarray), np.ndarray if PD_LTE_23 else pd.Index + assert_type(pd.unique(ri), np_1darray[np.int64]), + np.ndarray if PD_LTE_23 else pd.Index, + ) + check( + assert_type(pd.unique(tdi), np_1darray[np.timedelta64]), + np.ndarray if PD_LTE_23 else pd.Index, ) - check(assert_type(pd.unique(mi), np.ndarray), np.ndarray if PD_LTE_23 else pd.Index) + check(assert_type(pd.unique(mi), np_1darray), np.ndarray if PD_LTE_23 else pd.Index) check( assert_type(pd.unique(interval_i), "pd.IntervalIndex[pd.Interval[int]]"), pd.IntervalIndex, From 5cf045bcc15fc6ae7514e30f233006db6046cb51 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 10:32:36 +0100 Subject: [PATCH 03/11] resolve cut --- pandas-stubs/core/algorithms.pyi | 4 ++- pandas-stubs/core/reshape/tile.pyi | 39 ++++++++++++------------------ pandas-stubs/core/series.pyi | 28 ++++++++++----------- tests/series/test_series.py | 8 +++--- tests/test_pandas.py | 32 ++++++++++++------------ 5 files changed, 52 insertions(+), 59 deletions(-) diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index 441831161..6e4d2bd43 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -27,7 +27,9 @@ from pandas._typing import ( # with extension types return the same type while standard type return ndarray @overload -def unique(values: PeriodIndex) -> PeriodIndex: ... +def unique( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + values: PeriodIndex, +) -> PeriodIndex: ... @overload def unique( values: CategoricalIndex[S1, GenericT_co], diff --git a/pandas-stubs/core/reshape/tile.pyi b/pandas-stubs/core/reshape/tile.pyi index 0eed14683..8c985dc71 100644 --- a/pandas-stubs/core/reshape/tile.pyi +++ b/pandas-stubs/core/reshape/tile.pyi @@ -1,5 +1,6 @@ from collections.abc import Sequence from typing import ( + Any, Literal, overload, ) @@ -7,15 +8,14 @@ from typing import ( import numpy as np from pandas import ( Categorical, - CategoricalDtype, DatetimeIndex, Index, - Interval, IntervalIndex, Timestamp, ) from pandas.core.series import Series +from pandas._libs.interval import Interval from pandas._typing import ( IntervalT, Label, @@ -49,7 +49,7 @@ def cut( ordered: bool = ..., ) -> tuple[npt.NDArray[np.intp], IntervalIndex[IntervalT]]: ... @overload -def cut( # pyright: ignore[reportOverlappingOverload] +def cut( x: Series[Timestamp], bins: ( int @@ -66,7 +66,7 @@ def cut( # pyright: ignore[reportOverlappingOverload] include_lowest: bool = ..., duplicates: Literal["raise", "drop"] = ..., ordered: bool = ..., -) -> tuple[Series, DatetimeIndex]: ... +) -> tuple[Series[Any, Categorical], DatetimeIndex]: ... @overload def cut( x: Series[Timestamp], @@ -79,10 +79,10 @@ def cut( include_lowest: bool = ..., duplicates: Literal["raise", "drop"] = ..., ordered: bool = ..., -) -> tuple[Series, DatetimeIndex]: ... +) -> tuple[Series[Any, Categorical], DatetimeIndex]: ... @overload def cut( - x: Series, + x: Series[int] | Series[float], bins: int | Series | Index[int] | Index[float] | Sequence[int] | Sequence[float], right: bool = ..., labels: Literal[False] | Sequence[Label] | None = ..., @@ -92,10 +92,10 @@ def cut( include_lowest: bool = ..., duplicates: Literal["raise", "drop"] = ..., ordered: bool = ..., -) -> tuple[Series, npt.NDArray]: ... +) -> tuple[Series[Any, Categorical], npt.NDArray]: ... @overload def cut( - x: Series, + x: Series[int] | Series[float], bins: IntervalIndex[Interval[int]] | IntervalIndex[Interval[float]], right: bool = ..., labels: Sequence[Label] | None = ..., @@ -105,7 +105,7 @@ def cut( include_lowest: bool = ..., duplicates: Literal["raise", "drop"] = ..., ordered: bool = ..., -) -> tuple[Series, IntervalIndex]: ... +) -> tuple[Series[Any, Categorical], IntervalIndex]: ... @overload def cut( x: Index | npt.NDArray | Sequence[int] | Sequence[float], @@ -158,11 +158,10 @@ def cut( x: Series[Timestamp], bins: ( int - | Series[Timestamp] + | Sequence[np.datetime64 | Timestamp] | DatetimeIndex - | Sequence[Timestamp] - | Sequence[np.datetime64] | IntervalIndex[Interval[Timestamp]] + | Series[Timestamp] ), right: bool = ..., labels: Literal[False] | Sequence[Label] | None = ..., @@ -171,19 +170,11 @@ def cut( include_lowest: bool = ..., duplicates: Literal["raise", "drop"] = ..., ordered: bool = ..., -) -> Series[CategoricalDtype]: ... +) -> Series[Any, Categorical]: ... @overload def cut( - x: Series, - bins: ( - int - | Series - | Index[int] - | Index[float] - | Sequence[int] - | Sequence[float] - | IntervalIndex - ), + x: Series[int] | Series[float], + bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series, right: bool = ..., labels: Literal[False] | Sequence[Label] | None = ..., retbins: Literal[False] = False, @@ -191,7 +182,7 @@ def cut( include_lowest: bool = ..., duplicates: Literal["raise", "drop"] = ..., ordered: bool = ..., -) -> Series: ... +) -> Series[Any, Categorical]: ... @overload def cut( x: Index | npt.NDArray | Sequence[int] | Sequence[float], diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 3394b3203..a01cc1e60 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -47,13 +47,6 @@ from matplotlib.axes import ( SubplotBase, ) import numpy as np -from pandas import ( - Index, - Period, - PeriodDtype, - Timedelta, - Timestamp, -) from pandas.core.api import ( Int8Dtype as Int8Dtype, Int16Dtype as Int16Dtype, @@ -61,7 +54,10 @@ from pandas.core.api import ( Int64Dtype as Int64Dtype, ) from pandas.core.arrays.boolean import BooleanDtype -from pandas.core.arrays.categorical import CategoricalAccessor +from pandas.core.arrays.categorical import ( + Categorical, + CategoricalAccessor, +) from pandas.core.arrays.datetimes import DatetimeArray from pandas.core.arrays.timedeltas import TimedeltaArray from pandas.core.base import ( @@ -81,6 +77,7 @@ from pandas.core.groupby.generic import SeriesGroupBy from pandas.core.groupby.groupby import BaseGroupBy from pandas.core.indexers import BaseIndexer from pandas.core.indexes.accessors import DtDescriptor +from pandas.core.indexes.base import Index from pandas.core.indexes.category import CategoricalIndex from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.interval import IntervalIndex @@ -117,6 +114,9 @@ from pandas._libs.lib import _NoDefaultDoNotUse from pandas._libs.missing import NAType from pandas._libs.tslibs import BaseOffset from pandas._libs.tslibs.nattype import NaTType +from pandas._libs.tslibs.period import Period +from pandas._libs.tslibs.timedeltas import Timedelta +from pandas._libs.tslibs.timestamps import Timestamp from pandas._typing import ( S1, S2, @@ -216,7 +216,7 @@ from pandas._typing import ( ) from pandas.core.dtypes.base import ExtensionDtype -from pandas.core.dtypes.dtypes import CategoricalDtype +from pandas.core.dtypes.dtypes import PeriodDtype from pandas.plotting import PlotAccessor @@ -387,7 +387,7 @@ class Series(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1], NDFrame dtype: CategoryDtypeArg, name: Hashable = ..., copy: bool = ..., - ) -> Series[CategoricalDtype]: ... + ) -> Series[Any, Categorical]: ... @overload def __new__( cls, @@ -863,9 +863,9 @@ class Series(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1], NDFrame @overload def unique(self: Series[Never]) -> np.ndarray: ... @overload - def unique(self: Series[Timestamp]) -> DatetimeArray: ... # type: ignore[overload-overlap] + def unique(self: Series[Timestamp]) -> DatetimeArray: ... @overload - def unique(self: Series[Timedelta]) -> TimedeltaArray: ... # type: ignore[overload-overlap] + def unique(self: Series[Timedelta]) -> TimedeltaArray: ... @overload def unique(self) -> np.ndarray: ... @overload @@ -1449,7 +1449,7 @@ class Series(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1], NDFrame dtype: CategoryDtypeArg, copy: _bool = ..., errors: IgnoreRaise = ..., - ) -> Series[CategoricalDtype]: ... + ) -> Series[S1, Categorical]: ... @overload def astype( self, @@ -3625,7 +3625,7 @@ class Series(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1], NDFrame axis: int = 0, ) -> Series[BaseOffset]: ... @overload - def __truediv__( # type: ignore[overload-overlap] + def __truediv__( self: Series[Never], other: complex | NumListLike | Index | Series ) -> Series: ... @overload diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 15032eaf8..ae21649bc 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -50,8 +50,6 @@ Scalar, ) -from pandas.core.dtypes.dtypes import CategoricalDtype # noqa F401 - from tests import ( PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, @@ -1827,7 +1825,7 @@ def test_categorical_codes() -> None: # GH1383 sr = pd.Series([1], dtype="category") - check(assert_type(sr, "pd.Series[CategoricalDtype]"), pd.Series, np.integer) + check(assert_type(sr, "pd.Series[Any, pd.Categorical]"), pd.Series, np.integer) def test_relops() -> None: @@ -2915,8 +2913,8 @@ def test_astype_categorical(cast_arg: CategoryDtypeArg, target_type: type) -> No if TYPE_CHECKING: # pandas category - assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[pd.CategoricalDtype]") - assert_type(s.astype(cast_arg), "pd.Series[pd.CategoricalDtype]") + assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[str, pd.Categorical]") + assert_type(s.astype(cast_arg), "pd.Series[str, pd.Categorical]") @pytest.mark.parametrize("cast_arg, target_type", ASTYPE_OBJECT_ARGS, ids=repr) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 56d2c5c4b..9359a8683 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1030,9 +1030,13 @@ def test_cut() -> None: g = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, precision=1, duplicates="drop") h = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, labels=False, duplicates="raise") i = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, labels=["1", "2", "3", "4"]) - check(assert_type(g, pd.Series), pd.Series) - check(assert_type(h, pd.Series), pd.Series) - check(assert_type(i, pd.Series), pd.Series) + check(assert_type(g, pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval[float]) + check(assert_type(h, pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval[float]) + check( + assert_type(i, pd.Series[Any, pd.Categorical]), + pd.Series, + pd.Interval[float], + ) j0, j1 = pd.cut( pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), @@ -1059,13 +1063,13 @@ def test_cut() -> None: intval_idx, retbins=True, ) - check(assert_type(j0, pd.Series), pd.Series) + check(assert_type(j0, pd.Series[Any, pd.Categorical]), pd.Series) check(assert_type(j1, npt.NDArray), np.ndarray) - check(assert_type(k0, pd.Series), pd.Series) + check(assert_type(k0, pd.Series[Any, pd.Categorical]), pd.Series) check(assert_type(k1, npt.NDArray), np.ndarray) - check(assert_type(l0, pd.Series), pd.Series) + check(assert_type(l0, pd.Series[Any, pd.Categorical]), pd.Series) check(assert_type(l1, npt.NDArray), np.ndarray) - check(assert_type(m0, pd.Series), pd.Series) + check(assert_type(m0, pd.Series[Any, pd.Categorical]), pd.Series) check(assert_type(m1, pd.IntervalIndex), pd.IntervalIndex) n0, n1 = pd.cut([1, 2, 3, 4, 5, 6, 7, 8], intval_idx, retbins=True) @@ -1076,26 +1080,24 @@ def test_cut() -> None: check( assert_type( pd.cut(s1, bins=[np.datetime64("2020-01-03"), np.datetime64("2020-09-01")]), - "pd.Series[pd.CategoricalDtype]", + "pd.Series[Any, pd.Categorical]", ), pd.Series, + pd.Interval[pd.Timestamp], ) check( - assert_type( - pd.cut(s1, bins=10), - "pd.Series[pd.CategoricalDtype]", - ), + assert_type(pd.cut(s1, bins=10), pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval, ) s0r, s1r = pd.cut(s1, bins=10, retbins=True) - check(assert_type(s0r, pd.Series), pd.Series, pd.Interval) + check(assert_type(s0r, pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval) check(assert_type(s1r, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) s0rlf, s1rlf = pd.cut(s1, bins=10, labels=False, retbins=True) - check(assert_type(s0rlf, pd.Series), pd.Series, np.integer) + check(assert_type(s0rlf, pd.Series[Any, pd.Categorical]), pd.Series, np.integer) check(assert_type(s1rlf, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) s0rls, s1rls = pd.cut(s1, bins=4, labels=["1", "2", "3", "4"], retbins=True) - check(assert_type(s0rls, pd.Series), pd.Series, str) + check(assert_type(s0rls, pd.Series[Any, pd.Categorical]), pd.Series, str) check(assert_type(s1rls, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) From e4c4fb8b1bd9fa065b195f502b7b5a2d7f1ceb9d Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 10:51:06 +0100 Subject: [PATCH 04/11] pytest --- tests/test_pandas.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 9359a8683..220b882d9 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -665,7 +665,8 @@ def test_unique() -> None: pd.unique(pd.timedelta_range(start="1 day", periods=4)), np_1darray[np.timedelta64], ), - np_1darray[np.timedelta64] if PD_LTE_23 else pd.Index, + np_1darray if PD_LTE_23 else pd.Index, + np.timedelta64 if PD_LTE_23 else pd.Timedelta, ) @@ -984,10 +985,11 @@ def test_index_unqiue() -> None: mi = pd.MultiIndex.from_product([["a", "b"], ["apple", "banana"]]) interval_i = pd.interval_range(1, 10, periods=10) - check(assert_type(pd.unique(ci), pd.CategoricalIndex[str]), pd.CategoricalIndex) + check(assert_type(pd.unique(ci), "pd.CategoricalIndex[str]"), pd.CategoricalIndex) check( assert_type(pd.unique(dti), np_1darray[np.datetime64]), np.ndarray if PD_LTE_23 else pd.Index, + np.datetime64 if PD_LTE_23 else pd.Timestamp, ) check(assert_type(pd.unique(i), np_1darray), np.ndarray if PD_LTE_23 else pd.Index) check(assert_type(pd.unique(pi), pd.PeriodIndex), pd.PeriodIndex) @@ -1030,13 +1032,9 @@ def test_cut() -> None: g = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, precision=1, duplicates="drop") h = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, labels=False, duplicates="raise") i = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, labels=["1", "2", "3", "4"]) - check(assert_type(g, pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval[float]) - check(assert_type(h, pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval[float]) - check( - assert_type(i, pd.Series[Any, pd.Categorical]), - pd.Series, - pd.Interval[float], - ) + check(assert_type(g, "pd.Series[Any, pd.Categorical]"), pd.Series, pd.Interval) + check(assert_type(h, "pd.Series[Any, pd.Categorical]"), pd.Series, np.integer) + check(assert_type(i, "pd.Series[Any, pd.Categorical]"), pd.Series, str) j0, j1 = pd.cut( pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), @@ -1063,13 +1061,13 @@ def test_cut() -> None: intval_idx, retbins=True, ) - check(assert_type(j0, pd.Series[Any, pd.Categorical]), pd.Series) + check(assert_type(j0, "pd.Series[Any, pd.Categorical]"), pd.Series) check(assert_type(j1, npt.NDArray), np.ndarray) - check(assert_type(k0, pd.Series[Any, pd.Categorical]), pd.Series) + check(assert_type(k0, "pd.Series[Any, pd.Categorical]"), pd.Series) check(assert_type(k1, npt.NDArray), np.ndarray) - check(assert_type(l0, pd.Series[Any, pd.Categorical]), pd.Series) + check(assert_type(l0, "pd.Series[Any, pd.Categorical]"), pd.Series) check(assert_type(l1, npt.NDArray), np.ndarray) - check(assert_type(m0, pd.Series[Any, pd.Categorical]), pd.Series) + check(assert_type(m0, "pd.Series[Any, pd.Categorical]"), pd.Series) check(assert_type(m1, pd.IntervalIndex), pd.IntervalIndex) n0, n1 = pd.cut([1, 2, 3, 4, 5, 6, 7, 8], intval_idx, retbins=True) @@ -1083,21 +1081,21 @@ def test_cut() -> None: "pd.Series[Any, pd.Categorical]", ), pd.Series, - pd.Interval[pd.Timestamp], + float, ) check( - assert_type(pd.cut(s1, bins=10), pd.Series[Any, pd.Categorical]), + assert_type(pd.cut(s1, bins=10), "pd.Series[Any, pd.Categorical]"), pd.Series, pd.Interval, ) s0r, s1r = pd.cut(s1, bins=10, retbins=True) - check(assert_type(s0r, pd.Series[Any, pd.Categorical]), pd.Series, pd.Interval) + check(assert_type(s0r, "pd.Series[Any, pd.Categorical]"), pd.Series, pd.Interval) check(assert_type(s1r, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) s0rlf, s1rlf = pd.cut(s1, bins=10, labels=False, retbins=True) - check(assert_type(s0rlf, pd.Series[Any, pd.Categorical]), pd.Series, np.integer) + check(assert_type(s0rlf, "pd.Series[Any, pd.Categorical]"), pd.Series, np.integer) check(assert_type(s1rlf, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) s0rls, s1rls = pd.cut(s1, bins=4, labels=["1", "2", "3", "4"], retbins=True) - check(assert_type(s0rls, pd.Series[Any, pd.Categorical]), pd.Series, str) + check(assert_type(s0rls, "pd.Series[Any, pd.Categorical]"), pd.Series, str) check(assert_type(s1rls, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) From c4d1bafb05c027172dd8a23dfe3a9da3fbb930ee Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 15:30:36 +0100 Subject: [PATCH 05/11] add NumpyExtensionArray --- pandas-stubs/_libs/arrays.pyi | 1 + pandas-stubs/core/arrays/_mixins.pyi | 5 +++++ pandas-stubs/core/arrays/numpy_.pyi | 6 ++++++ pandas-stubs/core/strings/object_array.pyi | 1 + 4 files changed, 13 insertions(+) create mode 100644 pandas-stubs/_libs/arrays.pyi create mode 100644 pandas-stubs/core/arrays/_mixins.pyi create mode 100644 pandas-stubs/core/strings/object_array.pyi diff --git a/pandas-stubs/_libs/arrays.pyi b/pandas-stubs/_libs/arrays.pyi new file mode 100644 index 000000000..740dc7469 --- /dev/null +++ b/pandas-stubs/_libs/arrays.pyi @@ -0,0 +1 @@ +class NDArrayBacked: ... diff --git a/pandas-stubs/core/arrays/_mixins.pyi b/pandas-stubs/core/arrays/_mixins.pyi new file mode 100644 index 000000000..c34cbd231 --- /dev/null +++ b/pandas-stubs/core/arrays/_mixins.pyi @@ -0,0 +1,5 @@ +from pandas.core.arrays.base import ExtensionArray + +from pandas._libs.arrays import NDArrayBacked + +class NDArrayBackedExtensionArray(NDArrayBacked, ExtensionArray): ... diff --git a/pandas-stubs/core/arrays/numpy_.pyi b/pandas-stubs/core/arrays/numpy_.pyi index 760d82e84..96a7a72a3 100644 --- a/pandas-stubs/core/arrays/numpy_.pyi +++ b/pandas-stubs/core/arrays/numpy_.pyi @@ -1,9 +1,12 @@ import numpy as np from numpy.lib.mixins import NDArrayOperatorsMixin +from pandas.core.arraylike import OpsMixin +from pandas.core.arrays._mixins import NDArrayBackedExtensionArray from pandas.core.arrays.base import ( ExtensionArray, ExtensionOpsMixin, ) +from pandas.core.strings.object_array import ObjectStringArrayMixin from pandas.core.dtypes.dtypes import ExtensionDtype @@ -14,3 +17,6 @@ class PandasDtype(ExtensionDtype): def itemsize(self) -> int: ... class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin): ... +class NumpyExtensionArray( + OpsMixin, NDArrayBackedExtensionArray, ObjectStringArrayMixin +): ... diff --git a/pandas-stubs/core/strings/object_array.pyi b/pandas-stubs/core/strings/object_array.pyi new file mode 100644 index 000000000..3fd853b0f --- /dev/null +++ b/pandas-stubs/core/strings/object_array.pyi @@ -0,0 +1 @@ +class ObjectStringArrayMixin: ... From 5a6d8663f7dff5cd894d38d2da9833877fe077c5 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 15:51:16 +0100 Subject: [PATCH 06/11] properties --- pandas-stubs/core/indexes/accessors.pyi | 27 ++++++++++++++----------- pandas-stubs/core/indexes/interval.pyi | 3 ++- tests/indexes/test_indexes.py | 8 ++++++-- tests/series/test_properties.py | 10 ++++++--- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index b87872d78..74303119c 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -14,10 +14,10 @@ from typing import ( import numpy as np from pandas.core.accessor import PandasDelegate -from pandas.core.arrays.base import ExtensionArray from pandas.core.arrays.categorical import Categorical from pandas.core.arrays.datetimes import DatetimeArray from pandas.core.arrays.interval import IntervalArray +from pandas.core.arrays.numpy_ import NumpyExtensionArray from pandas.core.arrays.period import PeriodArray from pandas.core.arrays.timedeltas import TimedeltaArray from pandas.core.base import ( @@ -49,8 +49,6 @@ from pandas._typing import ( np_ndarray_bool, ) -from pandas.core.dtypes.dtypes import CategoricalDtype - class Properties(PandasDelegate, NoNewAttributesMixin): ... _DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", bound=Series[int] | Index[int]) @@ -462,26 +460,31 @@ class DtDescriptor: class ArrayDescriptor: @overload def __get__( - self, instance: IndexOpsMixin[Never], owner: type[IndexOpsMixin] - ) -> ExtensionArray: ... + self, instance: IndexOpsMixin[Never, Never], owner: type[IndexOpsMixin] + ) -> NumpyExtensionArray: ... @overload def __get__( - self, instance: IndexOpsMixin[CategoricalDtype], owner: type[IndexOpsMixin] + self, instance: IndexOpsMixin[Never, Categorical], owner: type[IndexOpsMixin] ) -> Categorical: ... @overload def __get__( - self, instance: IndexOpsMixin[Interval], owner: type[IndexOpsMixin] + self, + instance: IndexOpsMixin[Interval, IntervalArray], + owner: type[IndexOpsMixin], ) -> IntervalArray: ... @overload def __get__( - self, instance: IndexOpsMixin[Timestamp], owner: type[IndexOpsMixin] + self, + instance: IndexOpsMixin[Timestamp, DatetimeArray], + owner: type[IndexOpsMixin], ) -> DatetimeArray: ... @overload def __get__( - self, instance: IndexOpsMixin[Timedelta], owner: type[IndexOpsMixin] + self, + instance: IndexOpsMixin[Timedelta, TimedeltaArray], + owner: type[IndexOpsMixin], ) -> TimedeltaArray: ... - # should be NumpyExtensionArray @overload def __get__( - self, instance: IndexOpsMixin, owner: type[IndexOpsMixin] - ) -> ExtensionArray: ... + self, instance: IndexOpsMixin[int, Never], owner: type[IndexOpsMixin] + ) -> NumpyExtensionArray: ... diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index 48f33b622..a9f45857b 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -11,6 +11,7 @@ from typing import ( import numpy as np import pandas as pd +from pandas.core.arrays.interval import IntervalArray from pandas.core.indexes.base import Index from pandas.core.indexes.extension import ExtensionIndex @@ -61,7 +62,7 @@ _TimestampLike: TypeAlias = pd.Timestamp | np.datetime64 | dt.datetime _TimedeltaLike: TypeAlias = pd.Timedelta | np.timedelta64 | dt.timedelta class IntervalIndex( - ExtensionIndex[IntervalT, IntervalIndex, np.object_], IntervalMixin + ExtensionIndex[IntervalT, IntervalArray, np.object_], IntervalMixin ): closed: IntervalClosedType diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index 6c25d5e13..88a5f043a 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -12,10 +12,10 @@ import numpy as np from numpy import typing as npt import pandas as pd -from pandas.core.arrays.base import ExtensionArray from pandas.core.arrays.categorical import Categorical from pandas.core.arrays.datetimes import DatetimeArray from pandas.core.arrays.interval import IntervalArray +from pandas.core.arrays.numpy_ import NumpyExtensionArray from pandas.core.arrays.timedeltas import TimedeltaArray from pandas.core.indexes.base import Index from pandas.core.indexes.category import CategoricalIndex @@ -1476,7 +1476,11 @@ def test_array_property() -> None: TimedeltaArray, pd.Timedelta, ) - check(assert_type(Index([1]).array, ExtensionArray), ExtensionArray, np.integer) + check( + assert_type(Index([1]).array, NumpyExtensionArray), + NumpyExtensionArray, + np.integer, + ) def test_to_series() -> None: diff --git a/tests/series/test_properties.py b/tests/series/test_properties.py index 21ce75931..f82c43bcb 100644 --- a/tests/series/test_properties.py +++ b/tests/series/test_properties.py @@ -2,9 +2,9 @@ import numpy as np from pandas.core.arrays import DatetimeArray -from pandas.core.arrays.base import ExtensionArray from pandas.core.arrays.categorical import Categorical from pandas.core.arrays.interval import IntervalArray +from pandas.core.arrays.numpy_ import NumpyExtensionArray from pandas.core.arrays.timedeltas import TimedeltaArray from pandas.core.frame import DataFrame from pandas.core.indexes.accessors import ( @@ -77,7 +77,11 @@ def test_property_array() -> None: TimedeltaArray, Timedelta, ) - check(assert_type(Series([1]).array, ExtensionArray), ExtensionArray, np.integer) + check( + assert_type(Series([1]).array, NumpyExtensionArray), + NumpyExtensionArray, + np.integer, + ) # python/mypy#19952: mypy believes ExtensionArray and its subclasses have a # conflict and gives Any for s.array - check(assert_type(Series([1, "s"]).array, ExtensionArray), ExtensionArray) # type: ignore[assert-type] + # check(assert_type(Series([1, "s"]).array, NumpyExtensionArray), NumpyExtensionArray) # type: ignore[assert-type] From e8c6a8926a44ff1b07121d8fddd8645fa934f5fe Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 16:12:48 +0100 Subject: [PATCH 07/11] wip --- pandas-stubs/core/indexes/base.pyi | 12 ++++-------- pandas-stubs/core/indexes/datetimes.pyi | 5 +++-- pandas-stubs/core/indexes/interval.pyi | 7 ++++--- pandas-stubs/core/indexes/timedeltas.pyi | 5 +++-- tests/indexes/test_indexes.py | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi index ed0bdd95d..8cab03cf1 100644 --- a/pandas-stubs/core/indexes/base.pyi +++ b/pandas-stubs/core/indexes/base.pyi @@ -475,19 +475,15 @@ class Index(IndexOpsMixin[S1, A1_co, GenericT_co], ElementOpsMixin[S1]): @overload def where( self, - cond: ( - Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool, A1_co] - ), - other: S1 | Series[S1, A1_co] | Self, + cond: Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool], + other: S1 | Series[S1] | Self, ) -> Self: ... @overload def where( self, - cond: ( - Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool, A1_co] - ), + cond: Sequence[bool] | np_ndarray_bool | BooleanArray | IndexOpsMixin[bool], other: Scalar | AnyArrayLike | None = None, - ) -> Index[Any, A1_co]: ... + ) -> Index: ... def __contains__(self, key: Hashable) -> bool: ... @final def __setitem__(self, key, value) -> None: ... diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 033d7fa31..ce5e312a5 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -20,13 +20,13 @@ from pandas import ( TimedeltaIndex, Timestamp, ) +from pandas.core.arrays.datetimes import DatetimeArray from pandas.core.indexes.accessors import DatetimeIndexProperties from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin from pandas.core.series import Series from typing_extensions import Self from pandas._typing import ( - A1_co, AxesData, DateAndDatetimeLike, Dtype, @@ -44,7 +44,8 @@ from pandas.core.dtypes.dtypes import DatetimeTZDtype from pandas.tseries.offsets import BaseOffset class DatetimeIndex( - DatetimeTimedeltaMixin[Timestamp, A1_co, np.datetime64], DatetimeIndexProperties + DatetimeTimedeltaMixin[Timestamp, DatetimeArray, np.datetime64], + DatetimeIndexProperties, ): def __new__( cls, diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index a9f45857b..3432c7771 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -25,6 +25,7 @@ from pandas._typing import ( Frequency, IntervalClosedType, IntervalT, + Just, Label, MaskType, np_1darray, @@ -44,7 +45,7 @@ _EdgesInt: TypeAlias = ( | Index[int] ) _EdgesFloat: TypeAlias = ( - Sequence[float] | npt.NDArray[np.float64] | pd.Series[float] | Index[float] + Sequence[Just[float]] | npt.NDArray[np.float64] | pd.Series[float] | Index[float] ) _EdgesTimestamp: TypeAlias = ( Sequence[DatetimeLike] @@ -77,7 +78,7 @@ class IntervalIndex( ) -> IntervalIndex[IntervalT]: ... @overload @classmethod - def from_breaks( # pyright: ignore[reportOverlappingOverload] + def from_breaks( cls, breaks: _EdgesInt, closed: IntervalClosedType = ..., @@ -117,7 +118,7 @@ class IntervalIndex( ) -> IntervalIndex[Interval[pd.Timedelta]]: ... @overload @classmethod - def from_arrays( # pyright: ignore[reportOverlappingOverload] + def from_arrays( cls, left: _EdgesInt, right: _EdgesInt, diff --git a/pandas-stubs/core/indexes/timedeltas.pyi b/pandas-stubs/core/indexes/timedeltas.pyi index 763eeb3b0..6d6be1976 100644 --- a/pandas-stubs/core/indexes/timedeltas.pyi +++ b/pandas-stubs/core/indexes/timedeltas.pyi @@ -11,6 +11,7 @@ from typing import ( ) import numpy as np +from pandas.core.arrays.timedeltas import TimedeltaArray from pandas.core.indexes.accessors import TimedeltaIndexProperties from pandas.core.indexes.base import Index from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin @@ -26,7 +27,6 @@ from pandas._libs import Timedelta from pandas._libs.tslibs import BaseOffset from pandas._libs.tslibs.period import Period from pandas._typing import ( - A1_co, AxesData, Frequency, Just, @@ -53,7 +53,8 @@ _DT_FACTOR: TypeAlias = dt.timedelta | np.timedelta64 | Timedelta _DT_FACTOR_SEQ: TypeAlias = _DT_FACTOR | Sequence[_DT_FACTOR] | np_ndarray_td class TimedeltaIndex( - DatetimeTimedeltaMixin[Timedelta, A1_co, np.timedelta64], TimedeltaIndexProperties + DatetimeTimedeltaMixin[Timedelta, TimedeltaArray, np.timedelta64], + TimedeltaIndexProperties, ): def __new__( cls, diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index 88a5f043a..ffa52283d 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -1555,7 +1555,7 @@ def test_index_where() -> None: val_idx = idx.where(mask, idx) check(assert_type(val_idx, "pd.Index[int]"), pd.Index, int) - val_sr = idx.where(mask, (idx).to_series()) + val_sr = idx.where(mask, idx.to_series()) check(assert_type(val_sr, "pd.Index[int]"), pd.Index, int) From 837e14cec981358662d9499e74e052bb27ff8ed3 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Sun, 2 Nov 2025 16:33:56 +0100 Subject: [PATCH 08/11] pyright happiness --- pandas-stubs/core/algorithms.pyi | 8 +++++++- pandas-stubs/core/indexes/accessors.pyi | 3 ++- tests/test_pandas.py | 15 ++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index 6e4d2bd43..b76f13d75 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -10,8 +10,10 @@ from pandas.api.extensions import ExtensionArray from pandas.core.arrays.categorical import Categorical from pandas.core.indexes.base import Index from pandas.core.indexes.category import CategoricalIndex +from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.interval import IntervalIndex from pandas.core.indexes.period import PeriodIndex +from pandas.core.indexes.timedeltas import TimedeltaIndex from pandas.core.series import Series from pandas._typing import ( @@ -37,7 +39,11 @@ def unique( @overload def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... @overload -def unique(values: Index[S1, np_1darray, GenericT_co]) -> np_1darray[GenericT_co]: ... +def unique(values: DatetimeIndex) -> DatetimeIndex | np_1darray[np.datetime64]: ... +@overload +def unique(values: TimedeltaIndex) -> TimedeltaIndex | np_1darray[np.timedelta64]: ... +@overload +def unique(values: Index[S1, Any, GenericT_co]) -> np_1darray[GenericT_co]: ... @overload def unique(values: Categorical) -> Categorical: ... @overload diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index 74303119c..5f698bd66 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -5,6 +5,7 @@ from datetime import ( tzinfo as _tzinfo, ) from typing import ( + Any, Generic, Literal, TypeVar, @@ -486,5 +487,5 @@ class ArrayDescriptor: ) -> TimedeltaArray: ... @overload def __get__( - self, instance: IndexOpsMixin[int, Never], owner: type[IndexOpsMixin] + self, instance: IndexOpsMixin[Any, Never], owner: type[IndexOpsMixin] ) -> NumpyExtensionArray: ... diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 220b882d9..aed6571f9 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -609,7 +609,7 @@ def test_unique() -> None: ] ) ), - np_1darray[np.datetime64], + pd.DatetimeIndex | np_1darray[np.datetime64], ), pd.DatetimeIndex, ) @@ -663,9 +663,9 @@ def test_unique() -> None: check( assert_type( pd.unique(pd.timedelta_range(start="1 day", periods=4)), - np_1darray[np.timedelta64], + pd.TimedeltaIndex | np_1darray[np.timedelta64], ), - np_1darray if PD_LTE_23 else pd.Index, + np_1darray if PD_LTE_23 else pd.TimedeltaIndex, np.timedelta64 if PD_LTE_23 else pd.Timedelta, ) @@ -987,8 +987,8 @@ def test_index_unqiue() -> None: check(assert_type(pd.unique(ci), "pd.CategoricalIndex[str]"), pd.CategoricalIndex) check( - assert_type(pd.unique(dti), np_1darray[np.datetime64]), - np.ndarray if PD_LTE_23 else pd.Index, + assert_type(pd.unique(dti), pd.DatetimeIndex | np_1darray[np.datetime64]), + np.ndarray if PD_LTE_23 else pd.DatetimeIndex, np.datetime64 if PD_LTE_23 else pd.Timestamp, ) check(assert_type(pd.unique(i), np_1darray), np.ndarray if PD_LTE_23 else pd.Index) @@ -998,8 +998,9 @@ def test_index_unqiue() -> None: np.ndarray if PD_LTE_23 else pd.Index, ) check( - assert_type(pd.unique(tdi), np_1darray[np.timedelta64]), - np.ndarray if PD_LTE_23 else pd.Index, + assert_type(pd.unique(tdi), pd.TimedeltaIndex | np_1darray[np.timedelta64]), + np_1darray if PD_LTE_23 else pd.TimedeltaIndex, + np.timedelta64 if PD_LTE_23 else pd.Timedelta, ) check(assert_type(pd.unique(mi), np_1darray), np.ndarray if PD_LTE_23 else pd.Index) check( From eaf2c250f79e18137c02b6390af8c172373b85b6 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Mon, 3 Nov 2025 22:23:27 +0100 Subject: [PATCH 09/11] a lot of arithmetic --- tests/indexes/arithmetic/bool/test_add.py | 23 ++++++++++++---- tests/indexes/arithmetic/bool/test_mul.py | 23 +++++++++++----- tests/indexes/arithmetic/bool/test_sub.py | 22 ++++++++++----- tests/indexes/arithmetic/bool/test_truediv.py | 19 +++++++++---- tests/indexes/arithmetic/complex/test_add.py | 21 +++++++++++---- tests/indexes/arithmetic/complex/test_mul.py | 21 ++++++++++----- tests/indexes/arithmetic/complex/test_sub.py | 21 ++++++++++----- .../arithmetic/complex/test_truediv.py | 17 ++++++++---- tests/indexes/arithmetic/float/test_add.py | 23 ++++++++++++---- tests/indexes/arithmetic/float/test_mul.py | 23 +++++++++++----- tests/indexes/arithmetic/float/test_sub.py | 23 +++++++++++----- .../indexes/arithmetic/float/test_truediv.py | 23 ++++++++++++---- tests/indexes/arithmetic/int/test_add.py | 23 ++++++++++++---- tests/indexes/arithmetic/int/test_mul.py | 27 ++++++++++++++----- tests/indexes/arithmetic/int/test_sub.py | 25 ++++++++++++----- tests/indexes/arithmetic/int/test_truediv.py | 23 ++++++++++++---- tests/indexes/arithmetic/str/test_add.py | 9 ++++--- tests/indexes/arithmetic/str/test_mul.py | 15 ++++++----- tests/series/arithmetic/bool/test_add.py | 23 ++++++++++++---- tests/series/arithmetic/bool/test_mul.py | 23 +++++++++++----- tests/series/arithmetic/bool/test_sub.py | 22 ++++++++++----- tests/series/arithmetic/bool/test_truediv.py | 19 +++++++++---- tests/series/arithmetic/complex/test_add.py | 21 +++++++++++---- tests/series/arithmetic/complex/test_mul.py | 21 ++++++++++----- tests/series/arithmetic/complex/test_sub.py | 23 +++++++++++----- .../series/arithmetic/complex/test_truediv.py | 17 ++++++++---- tests/series/arithmetic/float/test_add.py | 23 ++++++++++++---- .../series/arithmetic/float/test_floordiv.py | 15 ++++++++--- tests/series/arithmetic/float/test_mul.py | 27 ++++++++++++++----- tests/series/arithmetic/float/test_sub.py | 23 +++++++++++----- tests/series/arithmetic/float/test_truediv.py | 23 ++++++++++++---- tests/series/arithmetic/int/test_add.py | 23 ++++++++++++---- tests/series/arithmetic/int/test_floordiv.py | 3 +-- tests/series/arithmetic/int/test_mul.py | 27 ++++++++++++++----- tests/series/arithmetic/int/test_sub.py | 25 ++++++++++++----- tests/series/arithmetic/int/test_truediv.py | 23 ++++++++++++---- tests/series/arithmetic/str/test_add.py | 9 ++++--- tests/series/arithmetic/str/test_mul.py | 15 ++++++----- tests/series/arithmetic/timedelta/test_add.py | 14 +++++++--- .../arithmetic/timedelta/test_floordiv.py | 13 +++++---- tests/series/arithmetic/timedelta/test_mul.py | 19 +++++++++---- tests/series/arithmetic/timedelta/test_sub.py | 14 +++++++--- .../arithmetic/timedelta/test_truediv.py | 15 ++++++----- tests/series/arithmetic/timestamp/test_add.py | 10 ++++--- tests/series/arithmetic/timestamp/test_sub.py | 10 ++++--- 45 files changed, 651 insertions(+), 230 deletions(-) diff --git a/tests/indexes/arithmetic/bool/test_add.py b/tests/indexes/arithmetic/bool/test_add.py index b80a25b1d..21f33139e 100644 --- a/tests/indexes/arithmetic/bool/test_add.py +++ b/tests/indexes/arithmetic/bool/test_add.py @@ -1,5 +1,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 assert_type @@ -54,11 +55,23 @@ 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(i + left, "npt.NDArray[np.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]"), + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.bool_, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/bool/test_mul.py b/tests/indexes/arithmetic/bool/test_mul.py index a1980eb72..161ee475a 100644 --- a/tests/indexes/arithmetic/bool/test_mul.py +++ b/tests/indexes/arithmetic/bool/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -91,17 +90,29 @@ 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(i * left, "npt.NDArray[np.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]"), + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.bool_, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure] def test_mul_pd_index(left: "pd.Index[bool]") -> None: diff --git a/tests/indexes/arithmetic/bool/test_sub.py b/tests/indexes/arithmetic/bool/test_sub.py index faac659dd..1e627342c 100644 --- a/tests/indexes/arithmetic/bool/test_sub.py +++ b/tests/indexes/arithmetic/bool/test_sub.py @@ -1,8 +1,8 @@ +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, assert_type, ) @@ -56,7 +56,7 @@ def test_sub_numpy_array() -> None: c = np.array([1.1j, 2.2j, 4.1j], np.complex128) if TYPE_CHECKING_INVALID_USAGE: - assert_type(left - b, Never) + assert_type(left - b, Any) # pyright: ignore[reportAssertTypeFailure] check(assert_type(left - i, "pd.Index[int]"), pd.Index, np.integer) check(assert_type(left - f, "pd.Index[float]"), pd.Index, np.floating) check(assert_type(left - c, "pd.Index[complex]"), pd.Index, np.complexfloating) @@ -65,11 +65,19 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `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(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating) + assert_type(b - left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/bool/test_truediv.py b/tests/indexes/arithmetic/bool/test_truediv.py index 00d2571fa..7c2183f04 100644 --- a/tests/indexes/arithmetic/bool/test_truediv.py +++ b/tests/indexes/arithmetic/bool/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -71,11 +72,19 @@ def test_truediv_numpy_array(left: "pd.Index[bool]") -> None: # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Index` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: - assert_type(b / left, "npt.NDArray[np.float64]") - check(assert_type(i / left, "npt.NDArray[np.float64]"), pd.Index, np.floating) - check(assert_type(f / left, "npt.NDArray[np.float64]"), pd.Index, np.floating) + assert_type(b / left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) check( - assert_type(c / left, "npt.NDArray[np.complex128]"), + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/complex/test_add.py b/tests/indexes/arithmetic/complex/test_add.py index bf3f6a4c2..8dd1f33cc 100644 --- a/tests/indexes/arithmetic/complex/test_add.py +++ b/tests/indexes/arithmetic/complex/test_add.py @@ -1,5 +1,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 assert_type @@ -54,13 +55,23 @@ 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(i + left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating) check( - assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, ) check( - assert_type(c + left, "npt.NDArray[np.complex128]"), + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/complex/test_mul.py b/tests/indexes/arithmetic/complex/test_mul.py index 1d0c88f65..b018109f5 100644 --- a/tests/indexes/arithmetic/complex/test_mul.py +++ b/tests/indexes/arithmetic/complex/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -91,19 +90,29 @@ 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(i * left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating) check( - assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, ) check( - assert_type(c * left, "npt.NDArray[np.complex128]"), + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure] def test_mul_pd_index(left: "pd.Index[complex]") -> None: diff --git a/tests/indexes/arithmetic/complex/test_sub.py b/tests/indexes/arithmetic/complex/test_sub.py index 8df2892d1..421d1b418 100644 --- a/tests/indexes/arithmetic/complex/test_sub.py +++ b/tests/indexes/arithmetic/complex/test_sub.py @@ -1,7 +1,6 @@ -from typing import NoReturn +from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -56,13 +55,23 @@ 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 # `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(f - left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, + ) + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, ) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/complex/test_truediv.py b/tests/indexes/arithmetic/complex/test_truediv.py index 34057cad0..51b3509cf 100644 --- a/tests/indexes/arithmetic/complex/test_truediv.py +++ b/tests/indexes/arithmetic/complex/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import assert_type @@ -60,16 +61,22 @@ def test_truediv_numpy_array(left: "pd.Index[complex]") -> None: # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Index` with the correct element type. check( - assert_type(b / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, ) check( - assert_type(i / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, ) check( - assert_type(f / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.complexfloating, ) check( - assert_type(c / left, "npt.NDArray[np.complex128]"), + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/float/test_add.py b/tests/indexes/arithmetic/float/test_add.py index ce5a84f1f..e20bba569 100644 --- a/tests/indexes/arithmetic/float/test_add.py +++ b/tests/indexes/arithmetic/float/test_add.py @@ -1,5 +1,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 assert_type @@ -54,11 +55,23 @@ 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(i + left, "npt.NDArray[np.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]"), + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/float/test_mul.py b/tests/indexes/arithmetic/float/test_mul.py index 67f4d5f5d..3ffb5593f 100644 --- a/tests/indexes/arithmetic/float/test_mul.py +++ b/tests/indexes/arithmetic/float/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -91,18 +90,30 @@ 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(i * left, "npt.NDArray[np.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]"), + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) check( - assert_type(d * left, "npt.NDArray[np.timedelta64]"), + assert_type(d * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.TimedeltaIndex, pd.Timedelta, ) diff --git a/tests/indexes/arithmetic/float/test_sub.py b/tests/indexes/arithmetic/float/test_sub.py index c35a7a5a6..391f572ac 100644 --- a/tests/indexes/arithmetic/float/test_sub.py +++ b/tests/indexes/arithmetic/float/test_sub.py @@ -1,7 +1,6 @@ -from typing import NoReturn +from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -56,11 +55,23 @@ 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 # `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(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/float/test_truediv.py b/tests/indexes/arithmetic/float/test_truediv.py index 6e1cd074a..3591fe458 100644 --- a/tests/indexes/arithmetic/float/test_truediv.py +++ b/tests/indexes/arithmetic/float/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import assert_type @@ -62,11 +63,23 @@ def test_truediv_numpy_array(left: "pd.Index[float]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Series` with the correct element type. - check(assert_type(b / left, "npt.NDArray[np.float64]"), pd.Index, np.floating) - check(assert_type(i / left, "npt.NDArray[np.float64]"), 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]"), + assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/int/test_add.py b/tests/indexes/arithmetic/int/test_add.py index 2d3cc7c1d..68140281e 100644 --- a/tests/indexes/arithmetic/int/test_add.py +++ b/tests/indexes/arithmetic/int/test_add.py @@ -1,5 +1,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 assert_type @@ -54,11 +55,23 @@ 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(i + left, "npt.NDArray[np.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]"), + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/int/test_mul.py b/tests/indexes/arithmetic/int/test_mul.py index b7f4d0b7c..bb4fca503 100644 --- a/tests/indexes/arithmetic/int/test_mul.py +++ b/tests/indexes/arithmetic/int/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -91,17 +90,33 @@ 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(i * left, "npt.NDArray[np.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]"), + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) 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, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + pd.Timedelta, + ) def test_mul_pd_index(left: "pd.Index[int]") -> None: diff --git a/tests/indexes/arithmetic/int/test_sub.py b/tests/indexes/arithmetic/int/test_sub.py index dfc151b2e..ee1284ffd 100644 --- a/tests/indexes/arithmetic/int/test_sub.py +++ b/tests/indexes/arithmetic/int/test_sub.py @@ -1,7 +1,8 @@ -from typing import NoReturn +from typing import ( + Any, +) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -56,11 +57,23 @@ 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 # `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(f - left, "npt.NDArray[np.float64]"), pd.Index, np.floating) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.integer, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/int/test_truediv.py b/tests/indexes/arithmetic/int/test_truediv.py index 3b9c2d8a1..3b8f4780f 100644 --- a/tests/indexes/arithmetic/int/test_truediv.py +++ b/tests/indexes/arithmetic/int/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import assert_type @@ -62,11 +63,23 @@ def test_truediv_numpy_array(left: "pd.Index[int]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Series` with the correct element type. - check(assert_type(b / left, "npt.NDArray[np.float64]"), pd.Index, np.floating) - check(assert_type(i / left, "npt.NDArray[np.float64]"), 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]"), + assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + np.floating, + ) + check( + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Index, np.complexfloating, ) diff --git a/tests/indexes/arithmetic/str/test_add.py b/tests/indexes/arithmetic/str/test_add.py index d4783f98f..c83d9223a 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, @@ -61,12 +60,16 @@ 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, Any) # pyright: ignore[reportAssertTypeFailure] 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 # `Index`es. - check(assert_type(r0 + left, "npt.NDArray[np.str_]"), pd.Index, str) + check( + assert_type(r0 + left, Any), # pyright: ignore[reportAssertTypeFailure] + 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 ea3206a9a..824ef01bd 100644 --- a/tests/indexes/arithmetic/str/test_mul.py +++ b/tests/indexes/arithmetic/str/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -97,13 +96,17 @@ 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_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, str) + assert_type(b * left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + 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(f * left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(c * left, Any) # pyright: ignore[reportAssertTypeFailure] assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure] def test_mul_pd_index(left: "pd.Index[str]") -> None: diff --git a/tests/series/arithmetic/bool/test_add.py b/tests/series/arithmetic/bool/test_add.py index cd3959d08..c0ad809de 100644 --- a/tests/series/arithmetic/bool/test_add.py +++ b/tests/series/arithmetic/bool/test_add.py @@ -1,5 +1,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 assert_type @@ -77,11 +78,23 @@ 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(i + left, "npt.NDArray[np.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]"), + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.bool_, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/bool/test_mul.py b/tests/series/arithmetic/bool/test_mul.py index e9dcf9d79..abd1bb3b6 100644 --- a/tests/series/arithmetic/bool/test_mul.py +++ b/tests/series/arithmetic/bool/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -127,17 +126,29 @@ 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(i * left, "npt.NDArray[np.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]"), + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.bool_, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure] 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/bool/test_sub.py b/tests/series/arithmetic/bool/test_sub.py index 6517e253f..1a44a4160 100644 --- a/tests/series/arithmetic/bool/test_sub.py +++ b/tests/series/arithmetic/bool/test_sub.py @@ -1,8 +1,8 @@ +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, assert_type, ) @@ -84,7 +84,7 @@ def test_sub_numpy_array() -> None: c = np.array([1.1j, 2.2j, 4.1j], np.complex128) if TYPE_CHECKING_INVALID_USAGE: - assert_type(left - b, Never) + assert_type(left - b, Any) # pyright: ignore[reportAssertTypeFailure] check(assert_type(left - i, "pd.Series[int]"), pd.Series, np.integer) check(assert_type(left - f, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left - c, "pd.Series[complex]"), pd.Series, np.complexfloating) @@ -93,11 +93,19 @@ def test_sub_numpy_array() -> None: # checking, where our `__rsub__` cannot override. At runtime, they return # `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(f - left, "npt.NDArray[np.float64]"), pd.Series, np.floating) + assert_type(b - left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/bool/test_truediv.py b/tests/series/arithmetic/bool/test_truediv.py index d366f950d..181992ae3 100644 --- a/tests/series/arithmetic/bool/test_truediv.py +++ b/tests/series/arithmetic/bool/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -139,11 +140,19 @@ def test_truediv_numpy_array(left: "pd.Series[bool]") -> None: # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Series` with the correct element type. if TYPE_CHECKING_INVALID_USAGE: - assert_type(b / left, "npt.NDArray[np.float64]") - check(assert_type(i / left, "npt.NDArray[np.float64]"), pd.Series, np.floating) - check(assert_type(f / left, "npt.NDArray[np.float64]"), pd.Series, np.floating) + assert_type(b / left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) check( - assert_type(c / left, "npt.NDArray[np.complex128]"), + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/complex/test_add.py b/tests/series/arithmetic/complex/test_add.py index 4e0338979..2691a5299 100644 --- a/tests/series/arithmetic/complex/test_add.py +++ b/tests/series/arithmetic/complex/test_add.py @@ -1,5 +1,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 assert_type @@ -89,13 +90,23 @@ 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(i + left, "npt.NDArray[np.int64]"), pd.Series, np.complexfloating) check( - assert_type(f + left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, ) check( - assert_type(c + left, "npt.NDArray[np.complex128]"), + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/complex/test_mul.py b/tests/series/arithmetic/complex/test_mul.py index abd2056e5..c1ba9eb60 100644 --- a/tests/series/arithmetic/complex/test_mul.py +++ b/tests/series/arithmetic/complex/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -139,19 +138,29 @@ 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(i * left, "npt.NDArray[np.int64]"), pd.Series, np.complexfloating) check( - assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, ) check( - assert_type(c * left, "npt.NDArray[np.complex128]"), + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) if TYPE_CHECKING_INVALID_USAGE: assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure] 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/complex/test_sub.py b/tests/series/arithmetic/complex/test_sub.py index a58c31ae3..594193ea2 100644 --- a/tests/series/arithmetic/complex/test_sub.py +++ b/tests/series/arithmetic/complex/test_sub.py @@ -1,7 +1,8 @@ -from typing import NoReturn +from typing import ( + Any, +) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -91,13 +92,23 @@ 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` 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(f - left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating + assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, + ) + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, ) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/complex/test_truediv.py b/tests/series/arithmetic/complex/test_truediv.py index 1ad66e307..1ad2f210f 100644 --- a/tests/series/arithmetic/complex/test_truediv.py +++ b/tests/series/arithmetic/complex/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import assert_type @@ -180,16 +181,22 @@ def test_truediv_numpy_array(left: "pd.Series[complex]") -> None: # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Series` with the correct element type. check( - assert_type(b / left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating + assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, ) check( - assert_type(i / left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, ) check( - assert_type(f / left, "npt.NDArray[np.float64]"), pd.Series, np.complexfloating + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.complexfloating, ) check( - assert_type(c / left, "npt.NDArray[np.complex128]"), + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/float/test_add.py b/tests/series/arithmetic/float/test_add.py index 6318ebf24..dcbc31b38 100644 --- a/tests/series/arithmetic/float/test_add.py +++ b/tests/series/arithmetic/float/test_add.py @@ -1,5 +1,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 assert_type @@ -77,11 +78,23 @@ 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(i + left, "npt.NDArray[np.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]"), + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/float/test_floordiv.py b/tests/series/arithmetic/float/test_floordiv.py index 2eedc4ef3..d27ad3754 100644 --- a/tests/series/arithmetic/float/test_floordiv.py +++ b/tests/series/arithmetic/float/test_floordiv.py @@ -1,7 +1,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, @@ -93,9 +92,17 @@ def test_floordiv_numpy_array() -> 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. - assert_type(b // left, "npt.NDArray[np.int8]") - check(i // left, pd.Series, np.floating) - check(f // left, pd.Series, np.floating) + assert_type(b // left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i // left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f // left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) if TYPE_CHECKING_INVALID_USAGE: assert_type(c // left, Any) diff --git a/tests/series/arithmetic/float/test_mul.py b/tests/series/arithmetic/float/test_mul.py index d83468c06..e27774064 100644 --- a/tests/series/arithmetic/float/test_mul.py +++ b/tests/series/arithmetic/float/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -127,17 +126,33 @@ 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(i * left, "npt.NDArray[np.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]"), + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) 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, Any), # pyright: ignore[reportAssertTypeFailure] + 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/float/test_sub.py b/tests/series/arithmetic/float/test_sub.py index afad8dab5..6b5e22a9b 100644 --- a/tests/series/arithmetic/float/test_sub.py +++ b/tests/series/arithmetic/float/test_sub.py @@ -1,7 +1,6 @@ -from typing import NoReturn +from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -79,11 +78,23 @@ 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` 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(f - left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/float/test_truediv.py b/tests/series/arithmetic/float/test_truediv.py index 83c3da2f5..01c219f77 100644 --- a/tests/series/arithmetic/float/test_truediv.py +++ b/tests/series/arithmetic/float/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import assert_type @@ -122,11 +123,23 @@ def test_truediv_numpy_array(left: "pd.Series[float]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Series` with the correct element type. - check(assert_type(b / left, "npt.NDArray[np.float64]"), pd.Series, np.floating) - check(assert_type(i / left, "npt.NDArray[np.float64]"), 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]"), + assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/int/test_add.py b/tests/series/arithmetic/int/test_add.py index 8f544374a..5b1acca06 100644 --- a/tests/series/arithmetic/int/test_add.py +++ b/tests/series/arithmetic/int/test_add.py @@ -1,5 +1,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 assert_type @@ -77,11 +78,23 @@ 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(i + left, "npt.NDArray[np.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]"), + assert_type(b + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(i + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(f + left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c + left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/int/test_floordiv.py b/tests/series/arithmetic/int/test_floordiv.py index 0504d1074..613d016bd 100644 --- a/tests/series/arithmetic/int/test_floordiv.py +++ b/tests/series/arithmetic/int/test_floordiv.py @@ -1,7 +1,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, @@ -93,7 +92,7 @@ def test_floordiv_numpy_array() -> 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. - assert_type(b // left, "npt.NDArray[np.int8]") + assert_type(b // left, Any) # pyright: ignore[reportAssertTypeFailure] check(i // left, pd.Series, np.integer) check(f // left, pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: diff --git a/tests/series/arithmetic/int/test_mul.py b/tests/series/arithmetic/int/test_mul.py index e3c1c7f05..9d3a6ad01 100644 --- a/tests/series/arithmetic/int/test_mul.py +++ b/tests/series/arithmetic/int/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -127,17 +126,33 @@ 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(i * left, "npt.NDArray[np.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]"), + assert_type(b * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c * left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) 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, Any), # pyright: ignore[reportAssertTypeFailure] + 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/int/test_sub.py b/tests/series/arithmetic/int/test_sub.py index 28bcdd4f0..36bd2c2a1 100644 --- a/tests/series/arithmetic/int/test_sub.py +++ b/tests/series/arithmetic/int/test_sub.py @@ -1,7 +1,8 @@ -from typing import NoReturn +from typing import ( + Any, +) import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -79,11 +80,23 @@ 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` 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(f - left, "npt.NDArray[np.float64]"), pd.Series, np.floating) check( - assert_type(c - left, "npt.NDArray[np.complex128]"), + assert_type(b - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(i - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.integer, + ) + check( + assert_type(f - left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c - left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/int/test_truediv.py b/tests/series/arithmetic/int/test_truediv.py index 757173a3a..59e0670bd 100644 --- a/tests/series/arithmetic/int/test_truediv.py +++ b/tests/series/arithmetic/int/test_truediv.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import assert_type @@ -122,11 +123,23 @@ def test_truediv_numpy_array(left: "pd.Series[int]") -> None: # `numpy` typing gives the corresponding `ndarray`s in the static type # checking, where our `__rtruediv__` cannot override. At runtime, they return # `Series` with the correct element type. - check(assert_type(b / left, "npt.NDArray[np.float64]"), pd.Series, np.floating) - check(assert_type(i / left, "npt.NDArray[np.float64]"), 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]"), + assert_type(b / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(i / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(f / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) + check( + assert_type(c / left, Any), # pyright: ignore[reportAssertTypeFailure] pd.Series, np.complexfloating, ) diff --git a/tests/series/arithmetic/str/test_add.py b/tests/series/arithmetic/str/test_add.py index 78986f1ca..9864e8cf6 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, @@ -79,12 +78,16 @@ 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, Any) # pyright: ignore[reportAssertTypeFailure] 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 # `Series`. - check(assert_type(r0 + left, "npt.NDArray[np.str_]"), pd.Series, str) + check( + assert_type(r0 + left, Any), # pyright: ignore[reportAssertTypeFailure] + 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 ef272db26..9e32be947 100644 --- a/tests/series/arithmetic/str/test_mul.py +++ b/tests/series/arithmetic/str/test_mul.py @@ -5,7 +5,6 @@ from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -133,13 +132,17 @@ 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_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, str) + assert_type(b * left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + 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(f * left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(c * left, Any) # pyright: ignore[reportAssertTypeFailure] assert_type(s * left, Any) - assert_type(d * left, "npt.NDArray[np.timedelta64]") + assert_type(d * left, Any) # pyright: ignore[reportAssertTypeFailure] if TYPE_CHECKING_INVALID_USAGE: left.mul(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] diff --git a/tests/series/arithmetic/timedelta/test_add.py b/tests/series/arithmetic/timedelta/test_add.py index 4aee2bd02..7ef044c1a 100644 --- a/tests/series/arithmetic/timedelta/test_add.py +++ b/tests/series/arithmetic/timedelta/test_add.py @@ -2,9 +2,9 @@ datetime, timedelta, ) +from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -102,8 +102,16 @@ 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, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + pd.Timestamp, + ) + check( + assert_type(d + left, Any), # pyright: ignore[reportAssertTypeFailure] + 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_floordiv.py b/tests/series/arithmetic/timedelta/test_floordiv.py index bb267d583..2ea8806ab 100644 --- a/tests/series/arithmetic/timedelta/test_floordiv.py +++ b/tests/series/arithmetic/timedelta/test_floordiv.py @@ -5,7 +5,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, @@ -138,12 +137,16 @@ def test_floordiv_numpy_array() -> None: # checking, where our `__rfloordiv__` cannot override. At runtime, they lead to # 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(f // left, "npt.NDArray[np.float64]") + assert_type(b // left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(i // left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(f // left, Any) # pyright: ignore[reportAssertTypeFailure] 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, Any), # pyright: ignore[reportAssertTypeFailure] + 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..f2b1d0a38 100644 --- a/tests/series/arithmetic/timedelta/test_mul.py +++ b/tests/series/arithmetic/timedelta/test_mul.py @@ -1,5 +1,6 @@ +from typing import Any + import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd import pytest from typing_extensions import ( @@ -104,12 +105,20 @@ 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_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, pd.Timedelta) - check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, pd.Timedelta) + assert_type(b * left, Any) # pyright: ignore[reportAssertTypeFailure] + check( + assert_type(i * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + pd.Timedelta, + ) + check( + assert_type(f * left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + pd.Timedelta, + ) if TYPE_CHECKING_INVALID_USAGE: # We made it Never, but numpy takes over - assert_type(c * left, "npt.NDArray[np.complex128]") + assert_type(c * left, Any) # pyright: ignore[reportAssertTypeFailure] if TYPE_CHECKING_INVALID_USAGE: left.mul(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] diff --git a/tests/series/arithmetic/timedelta/test_sub.py b/tests/series/arithmetic/timedelta/test_sub.py index c50abed21..21e2e5baf 100644 --- a/tests/series/arithmetic/timedelta/test_sub.py +++ b/tests/series/arithmetic/timedelta/test_sub.py @@ -2,9 +2,9 @@ datetime, timedelta, ) +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, @@ -112,8 +112,16 @@ 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, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + pd.Timestamp, + ) + check( + assert_type(d - left, Any), # pyright: ignore[reportAssertTypeFailure] + 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/timedelta/test_truediv.py b/tests/series/arithmetic/timedelta/test_truediv.py index da7fad64f..3dc342d84 100644 --- a/tests/series/arithmetic/timedelta/test_truediv.py +++ b/tests/series/arithmetic/timedelta/test_truediv.py @@ -5,7 +5,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, @@ -164,12 +163,16 @@ def test_truediv_numpy_array() -> None: # checking, where our `__rtruediv__` cannot override. At runtime, they lead to # errors or pd.Series. if TYPE_CHECKING_INVALID_USAGE: - assert_type(b / left, "npt.NDArray[np.float64]") - assert_type(i / left, "npt.NDArray[np.float64]") - assert_type(f / left, "npt.NDArray[np.float64]") - assert_type(c / left, "npt.NDArray[np.complex128]") + assert_type(b / left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(i / left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(f / left, Any) # pyright: ignore[reportAssertTypeFailure] + assert_type(c / left, Any) # pyright: ignore[reportAssertTypeFailure] assert_type(s / left, Any) - check(assert_type(d / left, "npt.NDArray[np.float64]"), pd.Series, np.floating) + check( + assert_type(d / left, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + np.floating, + ) if TYPE_CHECKING_INVALID_USAGE: left.truediv(b) # 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..39046201c 100644 --- a/tests/series/arithmetic/timestamp/test_add.py +++ b/tests/series/arithmetic/timestamp/test_add.py @@ -2,9 +2,9 @@ datetime, timedelta, ) +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, @@ -120,10 +120,14 @@ 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, Any) # pyright: ignore[reportAssertTypeFailure] # 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, Any), # pyright: ignore[reportAssertTypeFailure] + 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..57f095b6d 100644 --- a/tests/series/arithmetic/timestamp/test_sub.py +++ b/tests/series/arithmetic/timestamp/test_sub.py @@ -2,9 +2,9 @@ datetime, timedelta, ) +from typing import Any import numpy as np -from numpy import typing as npt # noqa: F401 import pandas as pd from typing_extensions import assert_type @@ -109,9 +109,13 @@ 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, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Series, + pd.Timedelta, + ) if TYPE_CHECKING_INVALID_USAGE: - assert_type(d - left, "npt.NDArray[np.timedelta64]") + assert_type(d - left, Any) # pyright: ignore[reportAssertTypeFailure] 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) From 895cd01b5b31d0600f80ff4142c9034cb33aa7c7 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Mon, 3 Nov 2025 22:23:47 +0100 Subject: [PATCH 10/11] asthetic --- tests/test_frame.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/test_frame.py b/tests/test_frame.py index 6a3973905..f050aa50d 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1817,14 +1817,8 @@ def test_types_groupby_iter() -> None: df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]}) series_groupby = pd.Series([True, True, False], dtype=bool) first_group = next(iter(df.groupby(series_groupby))) - check( - assert_type(first_group[0], bool), - bool, - ) - check( - assert_type(first_group[1], pd.DataFrame), - pd.DataFrame, - ) + check(assert_type(first_group[0], bool), bool) + check(assert_type(first_group[1], pd.DataFrame), pd.DataFrame) def test_types_groupby_level() -> None: From 389e228050a51c295122f6fc6ee09fa55792ed6d Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Mon, 3 Nov 2025 22:24:00 +0100 Subject: [PATCH 11/11] one less ignore --- pandas-stubs/core/algorithms.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index b76f13d75..b46b55efd 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -29,7 +29,7 @@ from pandas._typing import ( # with extension types return the same type while standard type return ndarray @overload -def unique( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] +def unique( # pyright: ignore[reportOverlappingOverload] values: PeriodIndex, ) -> PeriodIndex: ... @overload