diff --git a/pandas-stubs/_libs/tslibs/period.pyi b/pandas-stubs/_libs/tslibs/period.pyi index 38ca48a2e..f121fc395 100644 --- a/pandas-stubs/_libs/tslibs/period.pyi +++ b/pandas-stubs/_libs/tslibs/period.pyi @@ -91,8 +91,6 @@ class Period(PeriodMixin): def __add__(self, other: _PeriodAddSub) -> Self: ... @overload def __add__(self, other: NaTType) -> NaTType: ... - @overload - def __add__(self, other: Index) -> PeriodIndex: ... # Ignored due to indecipherable error from mypy: # Forward operator "__add__" is not callable [misc] if sys.version_info >= (3, 11): @@ -104,12 +102,6 @@ class Period(PeriodMixin): @overload def __radd__(self, other: NaTType) -> NaTType: ... - # Real signature is -> PeriodIndex, but conflicts with Index.__add__ - # Changing Index is very hard due to Index inheritance - # Signatures of "__radd__" of "Period" and "__add__" of "Index" - # are unsafely overlapping - @overload - def __radd__(self, other: Index) -> PeriodIndex: ... # ignore[misc] here because we know all other comparisons # are False, so we use Literal[False] @overload diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi index 3cea147f9..308af041e 100644 --- a/pandas-stubs/_libs/tslibs/timedeltas.pyi +++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi @@ -13,6 +13,7 @@ from typing import ( ) import numpy as np +from numpy import typing as npt from pandas.core.indexes.base import Index from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.period import PeriodIndex @@ -30,7 +31,6 @@ from pandas._typing import ( TimeUnit, np_1darray, np_ndarray, - npt, ) class Components(NamedTuple): @@ -250,22 +250,24 @@ class Timedelta(timedelta): ) -> np_ndarray[ShapeT, np.int_]: ... # Override due to more types supported than timedelta @overload # type: ignore[override] - def __truediv__(self, other: timedelta | Timedelta | NaTType) -> float: ... + # pyrefly: ignore[bad-override] + def __truediv__(self, other: Just[int] | Just[float]) -> Self: ... @overload - def __truediv__(self, other: float) -> Self: ... + def __truediv__(self, other: Self | NaTType) -> float: ... @overload def __truediv__( self, other: np_ndarray[ShapeT, np.integer | np.floating] ) -> np_ndarray[ShapeT, np.timedelta64]: ... @overload - def __truediv__(self, other: Series[Timedelta]) -> Series[float]: ... - @overload - def __truediv__(self, other: Series[int]) -> Series[Timedelta]: ... + def __truediv__( + self, other: np_ndarray[ShapeT, np.timedelta64] + ) -> np_ndarray[ShapeT, np.floating]: ... @overload - def __truediv__(self, other: Series[float]) -> Series[Timedelta]: ... + def __rtruediv__(self, other: Self | NaTType) -> float: ... @overload - def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ... - def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ... + def __rtruediv__( + self, other: np_ndarray[ShapeT, np.timedelta64] + ) -> np_ndarray[ShapeT, np.floating]: ... # Override due to more types supported than timedelta @overload def __eq__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 213607f44..a2b329338 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -18,11 +18,9 @@ from typing import ( ) import numpy as np -from pandas import ( - DatetimeIndex, - TimedeltaIndex, -) from pandas.core.indexes.base import Index +from pandas.core.indexes.datetimes import DatetimeIndex +from pandas.core.indexes.timedeltas import TimedeltaIndex from pandas.core.series import Series from typing_extensions import ( Never, @@ -99,10 +97,9 @@ class Timestamp(datetime, SupportsIndex): def tz(self) -> _tzinfo | None: ... @property def fold(self) -> int: ... - if sys.version_info >= (3, 12): @classmethod - def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore + def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] cls, t: float, tz: _tzinfo | str | None = ... ) -> Self: ... else: diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 7d944d243..3f74a9b5d 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -25,6 +25,7 @@ from typing import ( overload, ) +from _typeshed import _T_contra import numpy as np from numpy import typing as npt import pandas as pd @@ -860,6 +861,9 @@ np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64] # Define shape and generic type variables with defaults similar to numpy GenericT = TypeVar("GenericT", bound=np.generic, default=Any) GenericT_co = TypeVar("GenericT_co", bound=np.generic, default=Any, covariant=True) +GenericT_contra = TypeVar( + "GenericT_contra", bound=np.generic, default=Any, contravariant=True +) ShapeT = TypeVar("ShapeT", bound=tuple[int, ...], default=tuple[Any, ...]) # Numpy ndarray with more ergonomic typevar np_ndarray: TypeAlias = np.ndarray[ShapeT, np.dtype[GenericT]] @@ -1114,4 +1118,10 @@ class Just(Protocol, Generic[T]): @override def __class__(self, t: type[T], /) -> None: ... +class SupportsTrueDiv(Protocol[_T_contra, _T_co]): + def __truediv__(self, x: _T_contra, /) -> _T_co: ... + +class SupportsRTrueDiv(Protocol[_T_contra, _T_co]): + def __rtruediv__(self, x: _T_contra, /) -> _T_co: ... + __all__ = ["npt", "type_t"] diff --git a/pandas-stubs/core/base.pyi b/pandas-stubs/core/base.pyi index ff497ecd3..ca81fff38 100644 --- a/pandas-stubs/core/base.pyi +++ b/pandas-stubs/core/base.pyi @@ -3,6 +3,7 @@ from collections.abc import ( Iterator, Sequence, ) +from datetime import timedelta from typing import ( Any, Generic, @@ -175,7 +176,6 @@ NumListLike: TypeAlias = ( | np_ndarray_complex | dict[str, np.ndarray] | Sequence[complex] - | IndexOpsMixin[complex] ) @type_check_only @@ -266,6 +266,38 @@ class ElementOpsMixin(Generic[S2]): def _proto_rmul( self: ElementOpsMixin[str], other: Just[int] | np.integer ) -> ElementOpsMixin[str]: ... + @overload + def _proto_truediv( + self: ElementOpsMixin[int], other: int | np.integer + ) -> ElementOpsMixin[float]: ... + @overload + def _proto_truediv( + self: ElementOpsMixin[float], other: float | np.floating + ) -> ElementOpsMixin[float]: ... + @overload + def _proto_truediv( + self: ElementOpsMixin[complex], other: complex | np.complexfloating + ) -> ElementOpsMixin[complex]: ... + @overload + def _proto_truediv( + self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64 + ) -> ElementOpsMixin[float]: ... + @overload + def _proto_rtruediv( + self: ElementOpsMixin[int], other: int | np.integer + ) -> ElementOpsMixin[float]: ... + @overload + def _proto_rtruediv( + self: ElementOpsMixin[float], other: float | np.floating + ) -> ElementOpsMixin[float]: ... + @overload + def _proto_rtruediv( + self: ElementOpsMixin[complex], other: complex | np.complexfloating + ) -> ElementOpsMixin[complex]: ... + @overload + def _proto_rtruediv( + self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64 + ) -> ElementOpsMixin[float]: ... @type_check_only class Supports_ProtoAdd(Protocol[_T_contra, S2]): @@ -282,3 +314,11 @@ class Supports_ProtoMul(Protocol[_T_contra, S2]): @type_check_only class Supports_ProtoRMul(Protocol[_T_contra, S2]): def _proto_rmul(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ... + +@type_check_only +class Supports_ProtoTrueDiv(Protocol[_T_contra, S2]): + def _proto_truediv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ... + +@type_check_only +class Supports_ProtoRTrueDiv(Protocol[_T_contra, S2]): + def _proto_rtruediv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ... diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi index fe5c42b24..d6b245983 100644 --- a/pandas-stubs/core/indexes/base.pyi +++ b/pandas-stubs/core/indexes/base.pyi @@ -9,6 +9,7 @@ from datetime import ( datetime, timedelta, ) +from pathlib import Path from typing import ( Any, ClassVar, @@ -42,11 +43,12 @@ from pandas import ( from pandas.core.base import ( ElementOpsMixin, IndexOpsMixin, - NumListLike, Supports_ProtoAdd, Supports_ProtoMul, Supports_ProtoRAdd, Supports_ProtoRMul, + Supports_ProtoRTrueDiv, + Supports_ProtoTrueDiv, ) from pandas.core.indexes.category import CategoricalIndex from pandas.core.strings.accessor import StringMethods @@ -511,6 +513,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): @overload def __add__(self, other: Index[Never]) -> Index: ... @overload + def __add__(self: Index[Never], other: Period) -> PeriodIndex: ... + @overload def __add__( self: Supports_ProtoAdd[_T_contra, S2], other: _T_contra | Sequence[_T_contra] ) -> Index[S2]: ... @@ -561,6 +565,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index ) -> Index: ... @overload + def __radd__(self: Index[Never], other: Period) -> PeriodIndex: ... + @overload def __radd__( self: Supports_ProtoRAdd[_T_contra, S2], other: _T_contra | Sequence[_T_contra], @@ -679,7 +685,9 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): @overload def __rsub__(self: Index[Never], other: DatetimeIndex) -> Never: ... # type: ignore[misc] @overload - def __rsub__(self: Index[Never], other: complex | NumListLike | Index) -> Index: ... + def __rsub__( + self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index + ) -> Index: ... @overload def __rsub__(self, other: Index[Never]) -> Index: ... @overload @@ -755,27 +763,12 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): def __mul__(self, other: np_ndarray_dt) -> Never: ... @overload def __mul__(self: Index[bool] | Index[complex], other: np_ndarray_td) -> Never: ... - # pandas-dev/pandas#62524: An index of Python native timedeltas can be - # produced, instead of a TimedeltaIndex, hence the overload - @overload - def __mul__( # type: ignore[overload-overlap] - self: Index[int] | Index[float], other: Sequence[timedelta] - ) -> Index[Timedelta]: ... @overload def __mul__( self: Index[int] | Index[float], other: timedelta | Sequence[Timedelta] | np.timedelta64 | np_ndarray_td, ) -> TimedeltaIndex: ... @overload - def __mul__( - self: Index[Timedelta], other: np_ndarray_bool | np_ndarray_complex - ) -> Never: ... - @overload - def __mul__( - self: Index[Timedelta], - other: np_ndarray_anyint | np_ndarray_float | Index[int] | Index[float], - ) -> Index[Timedelta]: ... - @overload def __mul__( self: Index[_str], other: ( @@ -833,27 +826,12 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): def __rmul__(self, other: np_ndarray_dt) -> Never: ... @overload def __rmul__(self: Index[bool] | Index[complex], other: np_ndarray_td) -> Never: ... - # pandas-dev/pandas#62524: An index of Python native timedeltas can be - # produced, instead of a TimedeltaIndex, hence the overload - @overload - def __rmul__( # type: ignore[overload-overlap] - self: Index[int] | Index[float], other: Sequence[timedelta] - ) -> Index[Timedelta]: ... @overload def __rmul__( self: Index[int] | Index[float], other: timedelta | Sequence[Timedelta] | np.timedelta64 | np_ndarray_td, ) -> TimedeltaIndex: ... @overload - def __rmul__( - self: Index[Timedelta], other: np_ndarray_bool | np_ndarray_complex - ) -> Never: ... - @overload - def __rmul__( - self: Index[Timedelta], - other: np_ndarray_anyint | np_ndarray_float | Index[int] | Index[float], - ) -> Index[Timedelta]: ... - @overload def __rmul__( self: Index[_str], other: ( @@ -902,18 +880,121 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]): def __rmul__( self: Index[T_COMPLEX], other: np_ndarray_complex | Index[complex] ) -> Index[complex]: ... + @overload + def __truediv__( + self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index + ) -> Index: ... + @overload + def __truediv__(self, other: Index[Never]) -> Index: ... + @overload + def __truediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ... + @overload + def __truediv__( + self: Supports_ProtoTrueDiv[_T_contra, S2], + other: _T_contra | Sequence[_T_contra], + ) -> Index[S2]: ... + @overload + def __truediv__( + self: Index[int], + other: np_ndarray_bool | Index[bool], + ) -> Index[float]: ... + @overload + def __truediv__( + self: Index[bool] | Index[int], + other: Just[int] | Sequence[int] | np_ndarray_anyint | Index[int], + ) -> Index[float]: ... + @overload + def __truediv__( + self: Index[float], + other: np_ndarray_bool | np_ndarray_anyint | Index[bool] | Index[int], + ) -> Index[float]: ... + @overload + def __truediv__( + self: Index[complex], + other: np_ndarray_bool | np_ndarray_anyint | Index[bool] | Index[int], + ) -> Index[complex]: ... + @overload + def __truediv__( + self: Index[bool] | Index[int], + other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float], + ) -> Index[float]: ... + @overload + def __truediv__( + self: Index[T_COMPLEX], + other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float], + ) -> Index[T_COMPLEX]: ... + @overload + def __truediv__( + self: Index[T_COMPLEX], + other: ( + Just[complex] + | Sequence[Just[complex]] + | np_ndarray_complex + | Index[complex] + ), + ) -> Index[complex]: ... + @overload + def __truediv__(self, other: Path) -> Index: ... + @overload + def __rtruediv__( + self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index + ) -> Index: ... + @overload + def __rtruediv__(self, other: Index[Never]) -> Index: ... + @overload + def __rtruediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ... + @overload + def __rtruediv__( + self: Supports_ProtoRTrueDiv[_T_contra, S2], + other: _T_contra | Sequence[_T_contra], + ) -> Index[S2]: ... + @overload + def __rtruediv__( + self: Index[int], other: np_ndarray_bool | Index[bool] + ) -> Index[float]: ... + @overload + def __rtruediv__( + self: Index[bool] | Index[int], + other: Just[int] | Sequence[int] | np_ndarray_anyint | Index[int], + ) -> Index[float]: ... + @overload + def __rtruediv__( # type: ignore[misc] + self: Index[float], + other: np_ndarray_bool | np_ndarray_anyint | Index[bool] | Index[int], + ) -> Index[float]: ... + @overload + def __rtruediv__( + self: Index[complex], + other: np_ndarray_bool | np_ndarray_anyint | Index[bool] | Index[int], + ) -> Index[complex]: ... + @overload + def __rtruediv__( + self: Index[bool] | Index[int], + other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float], + ) -> Index[float]: ... + @overload + def __rtruediv__( + self: Index[T_COMPLEX], + other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float], + ) -> Index[T_COMPLEX]: ... + @overload + def __rtruediv__( + self: Index[T_COMPLEX], + other: ( + Just[complex] + | Sequence[Just[complex]] + | np_ndarray_complex + | Index[complex] + ), + ) -> Index[complex]: ... + @overload + def __rtruediv__(self, other: Path) -> Index: ... def __floordiv__( self, other: float | Sequence[float] | Index[int] | Index[float] ) -> Self: ... def __rfloordiv__( self, other: float | Sequence[float] | Index[int] | Index[float] ) -> Self: ... - def __truediv__( - self, other: float | Sequence[float] | Index[int] | Index[float] - ) -> Self: ... - def __rtruediv__( - self, other: float | Sequence[float] | Index[int] | Index[float] - ) -> Self: ... def infer_objects(self, copy: bool = True) -> Self: ... @type_check_only diff --git a/pandas-stubs/core/indexes/timedeltas.pyi b/pandas-stubs/core/indexes/timedeltas.pyi index 16a865ddc..dd1a8b189 100644 --- a/pandas-stubs/core/indexes/timedeltas.pyi +++ b/pandas-stubs/core/indexes/timedeltas.pyi @@ -5,16 +5,14 @@ from collections.abc import ( import datetime as dt from typing import ( Literal, + TypeAlias, final, overload, ) import numpy as np -from pandas import ( - Index, - Period, -) from pandas.core.indexes.accessors import TimedeltaIndexProperties +from pandas.core.indexes.base import Index from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.period import PeriodIndex @@ -26,6 +24,7 @@ from typing_extensions import ( from pandas._libs import Timedelta from pandas._libs.tslibs import BaseOffset +from pandas._libs.tslibs.period import Period from pandas._typing import ( AxesData, Frequency, @@ -40,6 +39,18 @@ from pandas._typing import ( num, ) +_NUM_FACTOR: TypeAlias = Just[int] | Just[float] | np.integer | np.floating +_NUM_FACTOR_SEQ: TypeAlias = ( + _NUM_FACTOR + | Sequence[_NUM_FACTOR] + | np_ndarray_anyint + | np_ndarray_float + | Index[int] + | Index[float] +) +_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 ): @@ -89,43 +100,29 @@ class TimedeltaIndex( @overload # type: ignore[override] def __mul__(self, other: np_ndarray_bool | np_ndarray_complex) -> Never: ... @overload - def __mul__( - self, - other: ( - Just[int] - | Just[float] - | Sequence[Just[int]] - | Sequence[Just[float]] - | np_ndarray_anyint - | np_ndarray_float - | Index[int] - | Index[float] - ), - ) -> Self: ... + def __mul__(self, other: _NUM_FACTOR_SEQ) -> Self: ... @overload # type: ignore[override] def __rmul__(self, other: np_ndarray_bool | np_ndarray_complex) -> Never: ... @overload - def __rmul__( - self, - other: ( - Just[int] - | Just[float] - | Sequence[Just[int]] - | Sequence[Just[float]] - | np_ndarray_anyint - | np_ndarray_float - | Index[int] - | Index[float] - ), - ) -> Self: ... + def __rmul__(self, other: _NUM_FACTOR_SEQ) -> Self: ... @overload # type: ignore[override] - # pyrefly: ignore # bad-override - def __truediv__(self, other: float | Sequence[float]) -> Self: ... + def __truediv__( # pyrefly: ignore[bad-override] + self, other: np_ndarray_bool | np_ndarray_complex | np_ndarray_dt + ) -> Never: ... + @overload + def __truediv__(self, other: _NUM_FACTOR_SEQ) -> Self: ... @overload def __truediv__( # pyright: ignore[reportIncompatibleMethodOverride] - self, other: dt.timedelta | Sequence[dt.timedelta] + self, other: _DT_FACTOR_SEQ | Self + ) -> Index[float]: ... + @overload # type: ignore[override] + def __rtruediv__( # pyrefly: ignore[bad-override] + self, other: np_ndarray_bool | np_ndarray_complex | np_ndarray_dt + ) -> Never: ... + @overload + def __rtruediv__( # pyright: ignore[reportIncompatibleMethodOverride] + self, other: _DT_FACTOR_SEQ | Self ) -> Index[float]: ... - def __rtruediv__(self, other: dt.timedelta | Sequence[dt.timedelta]) -> Index[float]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] @overload # type: ignore[override] # pyrefly: ignore # bad-override def __floordiv__(self, other: num | Sequence[float]) -> Self: ... diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 5d54f24ca..8e8321830 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -72,6 +72,8 @@ from pandas.core.base import ( Supports_ProtoMul, Supports_ProtoRAdd, Supports_ProtoRMul, + Supports_ProtoRTrueDiv, + Supports_ProtoTrueDiv, ) from pandas.core.frame import DataFrame from pandas.core.generic import NDFrame @@ -122,7 +124,6 @@ from pandas._typing import ( S2_CT_NDT, S2_NSDT, T_COMPLEX, - T_INT, AggFuncTypeBase, AggFuncTypeDictFrame, AggFuncTypeSeriesToFrame, @@ -3568,80 +3569,82 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): def __truediv__(self: Series[bool], other: np_ndarray_bool) -> Never: ... @overload def __truediv__( - self: Series[bool], + self: Series[Timedelta], + other: np_ndarray_bool | np_ndarray_complex | np_ndarray_dt, + ) -> Never: ... + @overload + def __truediv__( + self: Supports_ProtoTrueDiv[_T_contra, S2], + other: _T_contra | Sequence[_T_contra], + ) -> Series[S2]: ... + @overload + def __truediv__( + self: Series[int], + other: np_ndarray_bool | Index[bool] | Series[bool], + ) -> Series[float]: ... + @overload + def __truediv__( + self: Series[bool] | Series[int], + other: Just[int] | Sequence[int] | np_ndarray_anyint | Index[int] | Series[int], + ) -> Series[float]: ... + @overload + def __truediv__( + self: Series[float], other: ( - Just[int] - | Just[float] - | Sequence[float] + np_ndarray_bool | np_ndarray_anyint - | np_ndarray_float + | Index[bool] | Index[int] - | Index[float] + | Series[bool] | Series[int] - | Series[float] ), ) -> Series[float]: ... @overload def __truediv__( - self: Series[bool], + self: Series[complex], other: ( - Just[complex] | Sequence[Just[complex]] | Index[complex] | Series[complex] + np_ndarray_bool + | np_ndarray_anyint + | Index[bool] + | Index[int] + | Series[bool] + | Series[int] ), ) -> Series[complex]: ... @overload def __truediv__( - self: Series[int], + self: Series[bool] | Series[int], other: ( - int - | Sequence[int] - | np_ndarray_bool - | np_ndarray_anyint + Just[float] + | Sequence[Just[float]] | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[float] + | Series[float] ), ) -> Series[float]: ... @overload def __truediv__( - self: Series[int], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], - ) -> Series[T_COMPLEX]: ... - @overload - def __truediv__( - self: Series[float], + self: Series[T_COMPLEX], other: ( - int - | Sequence[int] - | np_ndarray_bool - | np_ndarray_anyint + Just[float] + | Sequence[Just[float]] | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[float] + | Series[float] ), - ) -> Series[float]: ... - @overload - def __truediv__( - self: Series[float], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], ) -> Series[T_COMPLEX]: ... @overload def __truediv__( - self: Series[complex], + self: Series[T_COMPLEX], other: ( - T_COMPLEX - | Sequence[T_COMPLEX] - | np_ndarray_bool - | np_ndarray_anyint - | np_ndarray_float - | Index[T_COMPLEX] - | Series[T_COMPLEX] + Just[complex] + | Sequence[Just[complex]] + | np_ndarray_complex + | Index[complex] + | Series[complex] ), ) -> Series[complex]: ... @overload - def __truediv__( - self: Series[T_COMPLEX], other: np_ndarray_complex - ) -> Series[complex]: ... - @overload def __truediv__( self: Series[Timedelta], other: ( @@ -3660,19 +3663,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): @overload def __truediv__( self: Series[Timedelta], - other: np_ndarray_bool | np_ndarray_complex | np_ndarray_dt, - ) -> Never: ... - @overload - def __truediv__( - self: Series[Timedelta], - other: ( - timedelta - | Sequence[timedelta] - | np.timedelta64 - | np_ndarray_td - | TimedeltaIndex - | Series[Timedelta] - ), + other: np_ndarray_td | TimedeltaIndex | Series[Timedelta], ) -> Series[float]: ... @overload def __truediv__(self, other: Path) -> Series: ... @@ -3694,100 +3685,96 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): ) -> Series: ... @overload def truediv( - self: Series[bool], - other: ( - Just[int] - | Just[float] - | Sequence[float] - | np_ndarray_anyint - | np_ndarray_float - | Index[int] - | Index[float] - | Series[int] - | Series[float] - ), + self: Supports_ProtoTrueDiv[_T_contra, S2], + other: _T_contra | Sequence[_T_contra], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[float]: ... + ) -> Series[S2]: ... @overload def truediv( - self: Series[bool], - other: ( - Just[complex] | Sequence[Just[complex]] | Index[complex] | Series[complex] - ), + self: Series[int], + other: np_ndarray_bool | Index[bool] | Series[bool], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[complex]: ... + ) -> Series[float]: ... @overload def truediv( - self: Series[int], - other: ( - int - | Sequence[int] - | np_ndarray_bool - | np_ndarray_anyint - | np_ndarray_float - | Index[T_INT] - | Series[T_INT] - ), + self: Series[bool] | Series[int], + other: Just[int] | Sequence[int] | np_ndarray_anyint | Index[int] | Series[int], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, ) -> Series[float]: ... @overload def truediv( - self: Series[int], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], + self: Series[float], + other: ( + np_ndarray_bool + | np_ndarray_anyint + | Index[bool] + | Index[int] + | Series[bool] + | Series[int] + ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[T_COMPLEX]: ... + ) -> Series[float]: ... @overload def truediv( - self: Series[float], + self: Series[complex], other: ( - int - | Sequence[int] - | np_ndarray_bool + np_ndarray_bool | np_ndarray_anyint - | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[bool] + | Index[int] + | Series[bool] + | Series[int] ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[float]: ... + ) -> Series[complex]: ... @overload def truediv( - self: Series[float], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], + self: Series[bool] | Series[int], + other: ( + Just[float] + | Sequence[Just[float]] + | np_ndarray_float + | Index[float] + | Series[float] + ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[T_COMPLEX]: ... + ) -> Series[float]: ... @overload def truediv( - self: Series[complex], + self: Series[T_COMPLEX], other: ( - T_COMPLEX - | Sequence[T_COMPLEX] - | np_ndarray_bool - | np_ndarray_anyint + Just[float] + | Sequence[Just[float]] | np_ndarray_float - | Index[T_COMPLEX] - | Series[T_COMPLEX] + | Index[float] + | Series[float] ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[complex]: ... + ) -> Series[T_COMPLEX]: ... @overload def truediv( self: Series[T_COMPLEX], - other: np_ndarray_complex, + other: ( + Just[complex] + | Sequence[Just[complex]] + | np_ndarray_complex + | Index[complex] + | Series[complex] + ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, @@ -3814,14 +3801,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): @overload def truediv( self: Series[Timedelta], - other: ( - timedelta - | Sequence[timedelta] - | np.timedelta64 - | np_ndarray_td - | TimedeltaIndex - | Series[Timedelta] - ), + other: np_ndarray_td | TimedeltaIndex | Series[Timedelta], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, @@ -3845,98 +3825,96 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): def __rtruediv__(self: Series[bool], other: np_ndarray_bool) -> Never: ... @overload def __rtruediv__( - self: Series[bool], + self: Series[Timedelta], + other: np_ndarray_bool | np_ndarray_complex | np_ndarray_dt, + ) -> Never: ... + @overload + def __rtruediv__( + self: Supports_ProtoRTrueDiv[_T_contra, S2], + other: _T_contra | Sequence[_T_contra], + ) -> Series[S2]: ... + @overload + def __rtruediv__( + self: Series[int], other: np_ndarray_bool | Index[bool] | Series[bool] + ) -> Series[float]: ... + @overload + def __rtruediv__( + self: Series[bool] | Series[int], + other: Just[int] | Sequence[int] | np_ndarray_anyint | Index[int] | Series[int], + ) -> Series[float]: ... + @overload + def __rtruediv__( # type: ignore[misc] + self: Series[float], other: ( - Just[int] - | Just[float] - | Sequence[float] + np_ndarray_bool | np_ndarray_anyint - | np_ndarray_float + | Index[bool] | Index[int] - | Index[float] + | Series[bool] | Series[int] - | Series[float] ), ) -> Series[float]: ... @overload def __rtruediv__( - self: Series[bool], + self: Series[complex], other: ( - Just[complex] | Sequence[Just[complex]] | Index[complex] | Series[complex] + np_ndarray_bool + | np_ndarray_anyint + | Index[bool] + | Index[int] + | Series[bool] + | Series[int] ), ) -> Series[complex]: ... @overload def __rtruediv__( - self: Series[int], + self: Series[bool] | Series[int], other: ( - int - | Sequence[int] - | np_ndarray_bool - | np_ndarray_anyint + Just[float] + | Sequence[Just[float]] | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[float] + | Series[float] ), ) -> Series[float]: ... @overload def __rtruediv__( - self: Series[int], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], - ) -> Series[T_COMPLEX]: ... - @overload - def __rtruediv__( - self: Series[float], + self: Series[T_COMPLEX], other: ( - int - | Sequence[int] - | np_ndarray_bool - | np_ndarray_anyint + Just[float] + | Sequence[Just[float]] | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[float] + | Series[float] ), - ) -> Series[float]: ... - @overload - def __rtruediv__( - self: Series[float], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], ) -> Series[T_COMPLEX]: ... @overload def __rtruediv__( - self: Series[complex], + self: Series[T_COMPLEX], other: ( - T_COMPLEX - | Sequence[T_COMPLEX] - | np_ndarray_bool - | np_ndarray_anyint - | np_ndarray_float - | Index[T_COMPLEX] - | Series[T_COMPLEX] + Just[complex] + | Sequence[Just[complex]] + | np_ndarray_complex + | Index[complex] + | Series[complex] ), ) -> Series[complex]: ... @overload - def __rtruediv__( - self: Series[T_COMPLEX], other: np_ndarray_complex - ) -> Series[complex]: ... - @overload def __rtruediv__( self: Series[Timedelta], - other: ( - np_ndarray_bool | np_ndarray_anyint | np_ndarray_float | np_ndarray_complex - ), - ) -> Never: ... + other: np_ndarray_td | TimedeltaIndex | Series[Timedelta], + ) -> Series[float]: ... @overload def __rtruediv__( - self: Series[Timedelta], + self: Series[int] | Series[float], other: ( timedelta | Sequence[timedelta] - | np.timedelta64 | np_ndarray_td | TimedeltaIndex | Series[Timedelta] ), - ) -> Series[float]: ... + ) -> Series[Timedelta]: ... @overload def __rtruediv__(self, other: Path) -> Series: ... @overload @@ -3957,43 +3935,38 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): ) -> Series: ... @overload def rtruediv( - self: Series[bool], - other: ( - Just[int] - | Just[float] - | Sequence[float] - | np_ndarray_anyint - | np_ndarray_float - | Index[int] - | Index[float] - | Series[int] - | Series[float] - ), + self: Supports_ProtoRTrueDiv[_T_contra, S2], + other: _T_contra | Sequence[_T_contra], + level: Level | None = None, + fill_value: float | None = None, + axis: AxisIndex = 0, + ) -> Series[S2]: ... + @overload + def rtruediv( + self: Series[int], + other: np_ndarray_bool | Index[bool] | Series[bool], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, ) -> Series[float]: ... @overload def rtruediv( - self: Series[bool], - other: ( - Just[complex] | Sequence[Just[complex]] | Index[complex] | Series[complex] - ), + self: Series[bool] | Series[int], + other: Just[int] | Sequence[int] | np_ndarray_anyint | Index[int] | Series[int], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[complex]: ... + ) -> Series[float]: ... @overload def rtruediv( - self: Series[int], + self: Series[float], other: ( - int - | Sequence[int] - | np_ndarray_bool + np_ndarray_bool | np_ndarray_anyint - | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[bool] + | Index[int] + | Series[bool] + | Series[int] ), level: Level | None = None, fill_value: float | None = None, @@ -4001,23 +3974,28 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): ) -> Series[float]: ... @overload def rtruediv( - self: Series[int], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], + self: Series[complex], + other: ( + np_ndarray_bool + | np_ndarray_anyint + | Index[bool] + | Index[int] + | Series[bool] + | Series[int] + ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[T_COMPLEX]: ... + ) -> Series[complex]: ... @overload def rtruediv( - self: Series[float], + self: Series[bool] | Series[int], other: ( - int - | Sequence[int] - | np_ndarray_bool - | np_ndarray_anyint + Just[float] + | Sequence[Just[float]] | np_ndarray_float - | Index[T_INT] - | Series[T_INT] + | Index[float] + | Series[float] ), level: Level | None = None, fill_value: float | None = None, @@ -4025,23 +4003,27 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): ) -> Series[float]: ... @overload def rtruediv( - self: Series[float], - other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX], + self: Series[T_COMPLEX], + other: ( + Just[float] + | Sequence[Just[float]] + | np_ndarray_float + | Index[float] + | Series[float] + ), level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, ) -> Series[T_COMPLEX]: ... @overload def rtruediv( - self: Series[complex], + self: Series[T_COMPLEX], other: ( - T_COMPLEX - | Sequence[T_COMPLEX] - | np_ndarray_bool - | np_ndarray_anyint - | np_ndarray_float - | Index[T_COMPLEX] - | Series[T_COMPLEX] + Just[complex] + | Sequence[Just[complex]] + | np_ndarray_complex + | Index[complex] + | Series[complex] ), level: Level | None = None, fill_value: float | None = None, @@ -4049,19 +4031,18 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): ) -> Series[complex]: ... @overload def rtruediv( - self: Series[T_COMPLEX], - other: np_ndarray_complex, + self: Series[Timedelta], + other: np_ndarray_td | TimedeltaIndex | Series[Timedelta], level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[complex]: ... + ) -> Series[float]: ... @overload def rtruediv( - self: Series[Timedelta], + self: Series[bool] | Series[int] | Series[float], other: ( timedelta | Sequence[timedelta] - | np.timedelta64 | np_ndarray_td | TimedeltaIndex | Series[Timedelta] @@ -4069,7 +4050,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): level: Level | None = None, fill_value: float | None = None, axis: AxisIndex = 0, - ) -> Series[float]: ... + ) -> Series[Timedelta]: ... @overload def rtruediv( self, diff --git a/tests/indexes/arithmetic/bool/test_mul.py b/tests/indexes/arithmetic/bool/test_mul.py index ad4b929d8..a1980eb72 100644 --- a/tests/indexes/arithmetic/bool/test_mul.py +++ b/tests/indexes/arithmetic/bool/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Index[bool]": - """left operand""" + """Left operand""" lo = pd.Index([True, True, False]) return check(assert_type(lo, "pd.Index[bool]"), pd.Index, np.bool_) diff --git a/tests/indexes/arithmetic/bool/test_truediv.py b/tests/indexes/arithmetic/bool/test_truediv.py new file mode 100644 index 000000000..00d2571fa --- /dev/null +++ b/tests/indexes/arithmetic/bool/test_truediv.py @@ -0,0 +1,101 @@ +import numpy as np +from numpy import typing as npt # noqa: F401 +import pandas as pd +import pytest +from typing_extensions import ( + Never, + assert_type, +) + +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) + + +@pytest.fixture +def left() -> "pd.Index[bool]": + """Left operand""" + lo = pd.Index([True, False, True]) + return check(assert_type(lo, "pd.Index[bool]"), pd.Index, np.bool_) + + +def test_truediv_py_scalar(left: "pd.Index[bool]") -> None: + """Test pd.Index[bool] / Python native scalars""" + b, i, f, c = True, 1, 1.0, 1j + + if TYPE_CHECKING_INVALID_USAGE: + # TODO: python/mypy#20061 + _00 = left / b # pyright: ignore[reportOperatorIssue] + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + if TYPE_CHECKING_INVALID_USAGE: + # TODO: python/mypy#20061 + _10 = b / left # pyright: ignore[reportOperatorIssue] + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_py_sequence(left: "pd.Index[bool]") -> None: + """Test pd.Index[bool] / Python native sequences""" + b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_numpy_array(left: "pd.Index[bool]") -> None: + """Test pd.Index[bool] / numpy arrays""" + b = np.array([True, False, True], np.bool_) + i = np.array([2, 3, 5], np.int64) + f = np.array([1.0, 2.0, 3.0], np.float64) + c = np.array([1.1j, 2.2j, 4.1j], np.complex128) + + if TYPE_CHECKING_INVALID_USAGE: + assert_type(left / b, Never) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + # `numpy` typing gives the corresponding `ndarray`s in the static type + # 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) + check( + assert_type(c / left, "npt.NDArray[np.complex128]"), + pd.Index, + np.complexfloating, + ) + + +def test_truediv_pd_index(left: "pd.Index[bool]") -> None: + """Test pd.Index[bool] / pandas Indexes""" + b = pd.Index([True, False, True]) + i = pd.Index([2, 3, 5]) + f = pd.Index([1.0, 2.0, 3.0]) + c = pd.Index([1.1j, 2.2j, 4.1j]) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + if TYPE_CHECKING_INVALID_USAGE: + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) diff --git a/tests/indexes/arithmetic/complex/test_mul.py b/tests/indexes/arithmetic/complex/test_mul.py index 136d4824b..1d0c88f65 100644 --- a/tests/indexes/arithmetic/complex/test_mul.py +++ b/tests/indexes/arithmetic/complex/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Index[complex]": - """left operand""" + """Left operand""" lo = pd.Index([1j, 2j, 3j]) return check(assert_type(lo, "pd.Index[complex]"), pd.Index, np.complexfloating) diff --git a/tests/indexes/arithmetic/complex/test_truediv.py b/tests/indexes/arithmetic/complex/test_truediv.py new file mode 100644 index 000000000..34057cad0 --- /dev/null +++ b/tests/indexes/arithmetic/complex/test_truediv.py @@ -0,0 +1,93 @@ +import numpy as np +from numpy import typing as npt # noqa: F401 +import pandas as pd +import pytest +from typing_extensions import assert_type + +from tests import check + + +@pytest.fixture +def left() -> "pd.Index[complex]": + """Left operand""" + lo = pd.Index([1j, 2j, 3j]) + return check(assert_type(lo, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_py_scalar(left: "pd.Index[complex]") -> None: + """Test pd.Index[complex] / Python native scalars""" + b, i, f, c = True, 1, 1.0, 1j + + check(assert_type(left / b, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / i, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / f, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(i / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(f / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_py_sequence(left: "pd.Index[complex]") -> None: + """Test pd.Index[complex] / Python native sequences""" + b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] + + check(assert_type(left / b, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / i, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / f, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(i / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(f / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_numpy_array(left: "pd.Index[complex]") -> None: + """Test pd.Index[complex] / numpy arrays""" + b = np.array([True, False, True], np.bool_) + i = np.array([2, 3, 5], np.int64) + f = np.array([1.0, 2.0, 3.0], np.float64) + c = np.array([1.1j, 2.2j, 4.1j], np.complex128) + + check(assert_type(left / b, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / i, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / f, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + # `numpy` typing gives the corresponding `ndarray`s in the static type + # 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 + ) + check( + assert_type(i / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + ) + check( + assert_type(f / left, "npt.NDArray[np.float64]"), pd.Index, np.complexfloating + ) + check( + assert_type(c / left, "npt.NDArray[np.complex128]"), + pd.Index, + np.complexfloating, + ) + + +def test_truediv_pd_index(left: "pd.Index[complex]") -> None: + """Test pd.Index[complex] / pandas Indexes""" + b = pd.Index([True, False, True]) + i = pd.Index([2, 3, 5]) + f = pd.Index([1.0, 2.0, 3.0]) + c = pd.Index([1.1j, 2.2j, 4.1j]) + + check(assert_type(left / b, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / i, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / f, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(i / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(f / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) diff --git a/tests/indexes/arithmetic/float/test_mul.py b/tests/indexes/arithmetic/float/test_mul.py index 45a1587e9..67f4d5f5d 100644 --- a/tests/indexes/arithmetic/float/test_mul.py +++ b/tests/indexes/arithmetic/float/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Index[float]": - """left operand""" + """Left operand""" lo = pd.Index([1.0, 2.0, 3.0]) return check(assert_type(lo, "pd.Index[float]"), pd.Index, np.floating) @@ -60,7 +60,7 @@ def test_mul_py_sequence(left: "pd.Index[float]") -> None: check(assert_type(left * c, "pd.Index[complex]"), pd.Index, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: _04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(left * d, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) + _05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(b * left, "pd.Index[float]"), pd.Index, np.floating) check(assert_type(i * left, "pd.Index[float]"), pd.Index, np.floating) @@ -68,7 +68,7 @@ def test_mul_py_sequence(left: "pd.Index[float]") -> None: check(assert_type(c * left, "pd.Index[complex]"), pd.Index, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: _14 = s * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(d * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) + _15 = d * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] def test_mul_numpy_array(left: "pd.Index[float]") -> None: diff --git a/tests/indexes/arithmetic/float/test_truediv.py b/tests/indexes/arithmetic/float/test_truediv.py new file mode 100644 index 000000000..6e1cd074a --- /dev/null +++ b/tests/indexes/arithmetic/float/test_truediv.py @@ -0,0 +1,103 @@ +import numpy as np +from numpy import typing as npt # noqa: F401 +import pandas as pd +import pytest +from typing_extensions import assert_type + +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) + + +@pytest.fixture +def left() -> "pd.Index[float]": + """Left operand""" + lo = pd.Index([1.0, 2.0, 3.0]) + return check(assert_type(lo, "pd.Index[float]"), pd.Index, np.floating) + + +def test_truediv_py_scalar(left: "pd.Index[float]") -> None: + """Test pd.Index[float] / Python native scalars""" + b, i, f, c = True, 1, 1.0, 1j + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_py_sequence(left: "pd.Index[float]") -> None: + """Test pd.Index[float] / Python native sequences""" + b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_numpy_array(left: "pd.Index[float]") -> None: + """Test pd.Index[float] / numpy arrays""" + b = np.array([True, False, True], np.bool_) + i = np.array([2, 3, 5], np.int64) + f = np.array([1.0, 2.0, 3.0], np.float64) + c = np.array([1.1j, 2.2j, 4.1j], np.complex128) + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + # `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]"), + pd.Index, + np.complexfloating, + ) + + +def test_truediv_pd_scalar(left: "pd.Index[float]") -> None: + """Test pd.Index[float] / pandas scalars""" + s, d = pd.Timestamp(2025, 9, 24), pd.Timedelta(seconds=1) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _01 = left / d # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + + if TYPE_CHECKING_INVALID_USAGE: + _10 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = d / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + + +def test_truediv_pd_index(left: "pd.Index[float]") -> None: + """Test pd.Index[float] / pandas Indexes""" + b = pd.Index([True, False, True]) + i = pd.Index([2, 3, 5]) + f = pd.Index([1.0, 2.0, 3.0]) + c = pd.Index([1.1j, 2.2j, 4.1j]) + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) diff --git a/tests/indexes/arithmetic/int/test_mul.py b/tests/indexes/arithmetic/int/test_mul.py index 69c49cad9..b7f4d0b7c 100644 --- a/tests/indexes/arithmetic/int/test_mul.py +++ b/tests/indexes/arithmetic/int/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Index[int]": - """left operand""" + """Left operand""" lo = pd.Index([1, 2, 3]) return check(assert_type(lo, "pd.Index[int]"), pd.Index, np.integer) @@ -60,9 +60,7 @@ def test_mul_py_sequence(left: "pd.Index[int]") -> None: check(assert_type(left * c, "pd.Index[complex]"), pd.Index, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: _04 = left * s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - # pandas-dev/pandas#62524: An index of Python native timedeltas can be - # produced, instead of a TimedeltaIndex, hence the test - check(assert_type(left * d, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) + _05 = left * d # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(b * left, "pd.Index[int]"), pd.Index, np.integer) check(assert_type(i * left, "pd.Index[int]"), pd.Index, np.integer) @@ -70,9 +68,7 @@ def test_mul_py_sequence(left: "pd.Index[int]") -> None: check(assert_type(c * left, "pd.Index[complex]"), pd.Index, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: _14 = s * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - # pandas-dev/pandas#62524: An index of Python native timedeltas can be - # produced, instead of a TimedeltaIndex, hence the test - check(assert_type(d * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) + _15 = d * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] def test_mul_numpy_array(left: "pd.Index[int]") -> None: diff --git a/tests/indexes/arithmetic/int/test_truediv.py b/tests/indexes/arithmetic/int/test_truediv.py new file mode 100644 index 000000000..3b9c2d8a1 --- /dev/null +++ b/tests/indexes/arithmetic/int/test_truediv.py @@ -0,0 +1,103 @@ +import numpy as np +from numpy import typing as npt # noqa: F401 +import pandas as pd +import pytest +from typing_extensions import assert_type + +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) + + +@pytest.fixture +def left() -> "pd.Index[int]": + """Left operand""" + lo = pd.Index([1, 2, 3]) + return check(assert_type(lo, "pd.Index[int]"), pd.Index, np.integer) + + +def test_truediv_py_scalar(left: "pd.Index[int]") -> None: + """Test pd.Index[int] / Python native scalars""" + b, i, f, c = True, 1, 1.0, 1j + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_py_sequence(left: "pd.Index[int]") -> None: + """Test pd.Index[int] / Python native sequences""" + b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) + + +def test_truediv_numpy_array(left: "pd.Index[int]") -> None: + """Test pd.Index[int] / numpy arrays""" + b = np.array([True, False, True], np.bool_) + i = np.array([2, 3, 5], np.int64) + f = np.array([1.0, 2.0, 3.0], np.float64) + c = np.array([1.1j, 2.2j, 4.1j], np.complex128) + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + # `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]"), + pd.Index, + np.complexfloating, + ) + + +def test_truediv_pd_scalar(left: "pd.Index[int]") -> None: + """Test pd.Index[int] / pandas scalars""" + s, d = pd.Timestamp(2025, 9, 24), pd.Timedelta(seconds=1) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _01 = left / d # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + + if TYPE_CHECKING_INVALID_USAGE: + _10 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = d / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + + +def test_truediv_pd_index(left: "pd.Index[int]") -> None: + """Test pd.Index[int] / pandas Indexes""" + b = pd.Index([True, False, True]) + i = pd.Index([2, 3, 5]) + f = pd.Index([1.0, 2.0, 3.0]) + c = pd.Index([1.1j, 2.2j, 4.1j]) + + check(assert_type(left / b, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / i, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / f, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(left / c, "pd.Index[complex]"), pd.Index, np.complexfloating) + + check(assert_type(b / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(i / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(f / left, "pd.Index[float]"), pd.Index, np.floating) + check(assert_type(c / left, "pd.Index[complex]"), pd.Index, np.complexfloating) diff --git a/tests/indexes/arithmetic/str/test_mul.py b/tests/indexes/arithmetic/str/test_mul.py index bc3aade00..ea3206a9a 100644 --- a/tests/indexes/arithmetic/str/test_mul.py +++ b/tests/indexes/arithmetic/str/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Index[str]": - """left operand""" + """Left operand""" lo = pd.Index(["1", "2", "3"]) return check(assert_type(lo, "pd.Index[str]"), pd.Index, str) diff --git a/tests/indexes/arithmetic/test_mul.py b/tests/indexes/arithmetic/test_mul.py index 5239e44dc..24eb5d50f 100644 --- a/tests/indexes/arithmetic/test_mul.py +++ b/tests/indexes/arithmetic/test_mul.py @@ -13,7 +13,7 @@ @pytest.fixture def left_i() -> pd.Index: - """left operand""" + """Left operand""" lo = pd.MultiIndex.from_tuples([(1,), (2,), (3,)]).levels[0] return check(assert_type(lo, pd.Index), pd.Index) diff --git a/tests/indexes/arithmetic/test_truediv.py b/tests/indexes/arithmetic/test_truediv.py new file mode 100644 index 000000000..3a6432912 --- /dev/null +++ b/tests/indexes/arithmetic/test_truediv.py @@ -0,0 +1,135 @@ +from pathlib import Path +from typing import Any + +import numpy as np +import pandas as pd +import pytest +from typing_extensions import assert_type + +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) + + +@pytest.fixture +def left_i() -> pd.Index: + """Left operand""" + lo = pd.MultiIndex.from_arrays([[1, 2, 3]]).levels[0] + return check(assert_type(lo, pd.Index), pd.Index, np.integer) + + +def test_truediv_py_scalar(left_i: pd.Index) -> None: + """Test pd.Index[Any] (int) / Python native scalars""" + b, i, f, c = True, 1, 1.0, 1j + + check(assert_type(left_i / b, pd.Index), pd.Index) + check(assert_type(left_i / i, pd.Index), pd.Index) + check(assert_type(left_i / f, pd.Index), pd.Index) + check(assert_type(left_i / c, pd.Index), pd.Index) + + check(assert_type(b / left_i, pd.Index), pd.Index) + check(assert_type(i / left_i, pd.Index), pd.Index) + check(assert_type(f / left_i, pd.Index), pd.Index) + check(assert_type(c / left_i, pd.Index), pd.Index) + + +def test_truediv_py_sequence(left_i: pd.Index) -> None: + """Test pd.Index[Any] (int) / Python native sequences""" + b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] + + check(assert_type(left_i / b, pd.Index), pd.Index) + check(assert_type(left_i / i, pd.Index), pd.Index) + check(assert_type(left_i / f, pd.Index), pd.Index) + check(assert_type(left_i / c, pd.Index), pd.Index) + + check(assert_type(b / left_i, pd.Index), pd.Index) + check(assert_type(i / left_i, pd.Index), pd.Index) + check(assert_type(f / left_i, pd.Index), pd.Index) + check(assert_type(c / left_i, pd.Index), pd.Index) + + +def test_truediv_numpy_array(left_i: pd.Index) -> None: + """Test pd.Index[Any] (int) / numpy arrays""" + b = np.array([True, False, True], np.bool_) + i = np.array([2, 3, 5], np.int64) + f = np.array([1.0, 2.0, 3.0], np.float64) + c = np.array([1.1j, 2.2j, 4.1j], np.complex64) + + check(assert_type(left_i / b, pd.Index), pd.Index) + check(assert_type(left_i / i, pd.Index), pd.Index) + check(assert_type(left_i / f, pd.Index), pd.Index) + check(assert_type(left_i / c, pd.Index), pd.Index) + + # `numpy` typing gives the corresponding `ndarray`s in the static type + # checking, where our `__rtruediv__` cannot override. At runtime, they return + # `Index`. + # microsoft/pyright#10924 + check( + assert_type(b / left_i, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + ) + check( + assert_type(i / left_i, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + ) + check( + assert_type(f / left_i, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + ) + check( + assert_type(c / left_i, Any), # pyright: ignore[reportAssertTypeFailure] + pd.Index, + ) + + +def test_truediv_pd_index(left_i: pd.Index) -> None: + """Test pd.Index[Any] (int) / pandas Indexes""" + a = pd.MultiIndex.from_tuples([(1,), (2,), (3,)]).levels[0] + b = pd.Index([True, False, True]) + i = pd.Index([2, 3, 5]) + f = pd.Index([1.0, 2.0, 3.0]) + c = pd.Index([1.1j, 2.2j, 4.1j]) + + check(assert_type(left_i / a, pd.Index), pd.Index) + check(assert_type(left_i / b, pd.Index), pd.Index) + check(assert_type(left_i / i, pd.Index), pd.Index) + check(assert_type(left_i / f, pd.Index), pd.Index) + check(assert_type(left_i / c, pd.Index), pd.Index) + + check(assert_type(a / left_i, pd.Index), pd.Index) + check(assert_type(b / left_i, pd.Index), pd.Index) + check(assert_type(i / left_i, pd.Index), pd.Index) + check(assert_type(f / left_i, pd.Index), pd.Index) + check(assert_type(c / left_i, pd.Index), pd.Index) + + +def test_truediv_paths(tmp_path: Path) -> None: + """Test pd.Index of paths / path object. + + Also GH 682.""" + fpath = Path("a.png") + folders, fpaths = pd.Index([tmp_path, tmp_path]), pd.Index([fpath, fpath]) + + check(assert_type(folders / fpath, pd.Index), pd.Index, Path) + + check(assert_type(tmp_path / fpaths, pd.Index), pd.Index, Path) + + +def test_truediv_path(tmp_path: Path) -> None: + """Test pd.Index / path object. + + Also GH 682.""" + fnames = pd.Index(["a.png", "b.gz", "c.txt"]) + + check(assert_type(fnames / tmp_path, pd.Index), pd.Index, Path) + check(assert_type(tmp_path / fnames, pd.Index), pd.Index, Path) + + +def test_truediv_str_py_str(left_i: pd.Index) -> None: + """Test pd.Index[Any] (int) / Python str""" + s = "abc" + + if TYPE_CHECKING_INVALID_USAGE: + _0 = left_i / s # type: ignore[operator] # pyright:ignore[reportOperatorIssue] + _1 = s / left_i # type: ignore[operator] # pyright:ignore[reportOperatorIssue] diff --git a/tests/indexes/arithmetic/timedelta/__init__.py b/tests/indexes/arithmetic/timedelta/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/indexes/arithmetic/timedelta/test_mul.py b/tests/indexes/arithmetic/timedelta/test_mul.py deleted file mode 100644 index 29b7e889a..000000000 --- a/tests/indexes/arithmetic/timedelta/test_mul.py +++ /dev/null @@ -1,110 +0,0 @@ -from datetime import timedelta - -import numpy as np -from numpy import typing as npt # noqa: F401 -import pandas as pd -import pytest -from typing_extensions import ( - Never, - assert_type, -) - -from tests import ( - TYPE_CHECKING_INVALID_USAGE, - check, -) - - -@pytest.fixture -def left() -> "pd.Index[pd.Timedelta]": - """left operand""" - # pandas-dev/pandas#62524: An index of Python native timedeltas can be - # produced, instead of a TimedeltaIndex, hence this test file - lo = pd.Index([1]) * [timedelta(seconds=1)] # left operand - return check(assert_type(lo, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - - -def test_mul_py_scalar(left: "pd.Index[pd.Timedelta]") -> None: - """Test pd.Index[pd.Timedelta] * Python native scalars""" - b, i, f, c = True, 1, 1.0, 1j - - if TYPE_CHECKING_INVALID_USAGE: - _00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(left * i, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(left * f, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - _03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - - if TYPE_CHECKING_INVALID_USAGE: - _10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(i * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(f * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - _13 = c * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - - -def test_mul_py_sequence(left: "pd.Index[pd.Timedelta]") -> None: - """Test pd.Index[pd.Timedelta] * Python native sequences""" - b, i, f, c = [True], [2], [1.5], [1.7j] - - if TYPE_CHECKING_INVALID_USAGE: - _00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(left * i, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(left * f, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - _03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - - if TYPE_CHECKING_INVALID_USAGE: - _10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(i * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(f * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - _13 = c * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - - -def test_mul_numpy_array(left: "pd.Index[pd.Timedelta]") -> None: - """Test pd.Index[pd.Timedelta] * numpy arrays""" - b = np.array([True], np.bool_) - i = np.array([2], np.int64) - f = np.array([1.5], np.float64) - c = np.array([1.7j], np.complex128) - - if TYPE_CHECKING_INVALID_USAGE: - assert_type(left * b, Never) - check(assert_type(left * i, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(left * f, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - assert_type(left * c, Never) - - # `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. - if TYPE_CHECKING_INVALID_USAGE: - assert_type(b * left, "npt.NDArray[np.bool_]") - check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Index, timedelta) - check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - # We made it Never, but numpy takes over - assert_type(c * left, "npt.NDArray[np.complex128]") - - -def test_mul_pd_index(left: "pd.Index[pd.Timedelta]") -> None: - """Test pd.Index[pd.Timedelta] * pandas Indexes""" - b = pd.Index([True]) - i = pd.Index([2]) - f = pd.Index([1.5]) - c = pd.Index([1.7j]) - - if TYPE_CHECKING_INVALID_USAGE: - _00 = left * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(left * i, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(left * f, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - _03 = left * c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - - if TYPE_CHECKING_INVALID_USAGE: - _10 = b * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - check(assert_type(i * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - check(assert_type(f * left, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) - if TYPE_CHECKING_INVALID_USAGE: - _13 = c * left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] diff --git a/tests/indexes/arithmetic/timedeltaindex/test_mul.py b/tests/indexes/arithmetic/timedeltaindex/test_mul.py index dcd329343..1ed7501cb 100644 --- a/tests/indexes/arithmetic/timedeltaindex/test_mul.py +++ b/tests/indexes/arithmetic/timedeltaindex/test_mul.py @@ -15,7 +15,7 @@ @pytest.fixture def left() -> pd.TimedeltaIndex: - """left operand""" + """Left operand""" lo = pd.Index([pd.Timedelta(1, "s")]) # left operand return check(assert_type(lo, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) diff --git a/tests/indexes/arithmetic/timedeltaindex/test_truediv.py b/tests/indexes/arithmetic/timedeltaindex/test_truediv.py new file mode 100644 index 000000000..16b5f216e --- /dev/null +++ b/tests/indexes/arithmetic/timedeltaindex/test_truediv.py @@ -0,0 +1,141 @@ +from datetime import ( + datetime, + timedelta, +) +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 ( + Never, + assert_type, +) + +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) + + +@pytest.fixture +def left() -> pd.TimedeltaIndex: + """Left operand""" + lo = pd.to_timedelta(["1 second"]) + return check(assert_type(lo, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + + +def test_truediv_py_scalar(left: pd.TimedeltaIndex) -> None: + """Test pd.TimedeltaIndex / Python native scalars""" + b, i, f, c = True, 1, 1.0, 1j + s, d = datetime(2025, 9, 24), timedelta(seconds=1) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / i, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + check(assert_type(left / f, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + if TYPE_CHECKING_INVALID_USAGE: + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / d, "pd.Index[float]"), pd.Index, np.floating) + + if TYPE_CHECKING_INVALID_USAGE: + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(d / left, "pd.Index[float]"), pd.Index, np.floating) + + +def test_truediv_py_sequence(left: pd.TimedeltaIndex) -> None: + """Test pd.TimedeltaIndex / Python native sequences""" + b, i, f, c = [True], [2], [1.5], [1.7j] + s, d = [datetime(2025, 9, 24)], [timedelta(seconds=1)] + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / i, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + check(assert_type(left / f, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + if TYPE_CHECKING_INVALID_USAGE: + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / d, "pd.Index[float]"), pd.Index, float) + + if TYPE_CHECKING_INVALID_USAGE: + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(d / left, "pd.Index[float]"), pd.Index, np.floating) + + +def test_truediv_numpy_array(left: pd.TimedeltaIndex) -> None: + """Test pd.TimedeltaIndex / numpy arrays""" + b = np.array([True], np.bool_) + i = np.array([2], np.int64) + f = np.array([1.5], np.float64) + c = np.array([1.7j], np.complex128) + s = np.array([datetime(2025, 9, 24)], np.datetime64) + d = np.array([timedelta(seconds=1)], np.timedelta64) + + if TYPE_CHECKING_INVALID_USAGE: + assert_type(left / b, Never) + check(assert_type(left / i, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + check(assert_type(left / f, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + if TYPE_CHECKING_INVALID_USAGE: + assert_type(left / c, Never) + assert_type(left / s, Never) + check(assert_type(left / d, "pd.Index[float]"), pd.Index, np.floating) + + # `numpy` typing gives the corresponding `ndarray`s in the static type + # 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(s / left, Any) + check(assert_type(d / left, "npt.NDArray[np.float64]"), pd.Index, np.floating) + + +def test_truediv_pd_scalar(left: pd.TimedeltaIndex) -> None: + """Test pd.TimedeltaIndex / pandas scalars""" + s, d = pd.Timestamp(2025, 9, 24), pd.Timedelta(seconds=1) + + if TYPE_CHECKING_INVALID_USAGE: + _0 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / d, "pd.Index[float]"), pd.Index, np.floating) + + if TYPE_CHECKING_INVALID_USAGE: + _1 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(d / left, "pd.Index[float]"), pd.Index, np.floating) + + +def test_truediv_pd_index(left: pd.TimedeltaIndex) -> None: + """Test pd.TimedeltaIndex / pandas pd.Indexes""" + b = pd.Index([True]) + i = pd.Index([2]) + f = pd.Index([1.5]) + c = pd.Index([1.7j]) + s, d = pd.Index([datetime(2025, 9, 24)]), pd.Index([timedelta(seconds=1)]) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / i, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + check(assert_type(left / f, pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta) + if TYPE_CHECKING_INVALID_USAGE: + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(left / d, "pd.Index[float]"), pd.Index, np.floating) + + if TYPE_CHECKING_INVALID_USAGE: + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(d / left, "pd.Index[float]"), pd.Index, np.floating) diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index 4db44276d..3b2960b3c 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -870,18 +870,6 @@ def test_index_operators() -> None: i1 = pd.Index([1, 2, 3]) i2 = pd.Index([4, 5, 6]) - check(assert_type(i1 + i2, "pd.Index[int]"), pd.Index) - check(assert_type(i1 + 10, "pd.Index[int]"), pd.Index) - check(assert_type(10 + i1, "pd.Index[int]"), pd.Index) - check(assert_type(i1 - i2, "pd.Index[int]"), pd.Index) - check(assert_type(i1 - 10, "pd.Index[int]"), pd.Index) - check(assert_type(10 - i1, "pd.Index[int]"), pd.Index) - check(assert_type(i1 * i2, "pd.Index[int]"), pd.Index) - check(assert_type(i1 * 10, "pd.Index[int]"), pd.Index) - check(assert_type(10 * i1, "pd.Index[int]"), pd.Index) - check(assert_type(i1 / i2, "pd.Index[int]"), pd.Index) - check(assert_type(i1 / 10, "pd.Index[int]"), pd.Index) - check(assert_type(10 / i1, "pd.Index[int]"), pd.Index) check(assert_type(i1 // i2, "pd.Index[int]"), pd.Index) check(assert_type(i1 // 10, "pd.Index[int]"), pd.Index) check(assert_type(10 // i1, "pd.Index[int]"), pd.Index) diff --git a/tests/scalars/test_scalars.py b/tests/scalars/test_scalars.py index 19b4aaf33..d4cafa390 100644 --- a/tests/scalars/test_scalars.py +++ b/tests/scalars/test_scalars.py @@ -755,19 +755,6 @@ def test_timedelta_mul_div() -> None: np.ndarray, np.timedelta64, ) - check( - assert_type(td / mp_series_int, "pd.Series[pd.Timedelta]"), - pd.Series, - pd.Timedelta, - ) - check( - assert_type(td / md_series_float, "pd.Series[pd.Timedelta]"), - pd.Series, - pd.Timedelta, - ) - check(assert_type(td / md_int64_index, pd.TimedeltaIndex), pd.TimedeltaIndex) - check(assert_type(td / md_float_index, pd.TimedeltaIndex), pd.TimedeltaIndex) - check(assert_type(td / md_timedelta_series, "pd.Series[float]"), pd.Series, float) check(assert_type(pd.NaT / td, float), float) # Note: None of the reverse truediv work @@ -778,10 +765,6 @@ def test_timedelta_mul_div() -> None: _11 = md_float / td # type: ignore[operator] # pyright: ignore[reportOperatorIssue] _12 = md_ndarray_intp / td # type: ignore[operator] # pyright: ignore[reportOperatorIssue] _13 = md_ndarray_float / td # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _14 = mp_series_int / td # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _15 = md_series_float / td # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _16 = (md_int64_index / td,) # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _17 = (md_float_index / td,) # type: ignore[operator] # pyright: ignore[reportOperatorIssue] def test_timedelta_mod_abs_unary() -> None: diff --git a/tests/series/arithmetic/bool/test_mul.py b/tests/series/arithmetic/bool/test_mul.py index ea98eb821..e9dcf9d79 100644 --- a/tests/series/arithmetic/bool/test_mul.py +++ b/tests/series/arithmetic/bool/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Series[bool]": - """left operand""" + """Left operand""" lo = pd.Series([True, True, False]) return check(assert_type(lo, "pd.Series[bool]"), pd.Series, np.bool_) diff --git a/tests/series/arithmetic/bool/test_truediv.py b/tests/series/arithmetic/bool/test_truediv.py index 41c0e1a52..d366f950d 100644 --- a/tests/series/arithmetic/bool/test_truediv.py +++ b/tests/series/arithmetic/bool/test_truediv.py @@ -1,6 +1,7 @@ import numpy as np from numpy import typing as npt # noqa: F401 import pandas as pd +import pytest from typing_extensions import ( Never, assert_type, @@ -11,27 +12,35 @@ check, ) -left = pd.Series([True, False, True]) # left operand +@pytest.fixture +def left() -> "pd.Series[bool]": + """Left operand""" + lo = pd.Series([True, False, True]) + return check(assert_type(lo, "pd.Series[bool]"), pd.Series, np.bool_) -def test_truediv_py_scalar() -> None: + +def test_truediv_py_scalar(left: "pd.Series[bool]") -> None: """Test pd.Series[bool] / Python native scalars""" b, i, f, c = True, 1, 1.0, 1j if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + # TODO: python/mypy#20061 + _00 = left / b # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left / f, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left / c, "pd.Series[complex]"), pd.Series, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: - _1 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + # TODO: python/mypy#20061 + _10 = b / left # pyright: ignore[reportOperatorIssue] check(assert_type(i / left, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(f / left, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(c / left, "pd.Series[complex]"), pd.Series, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: - left.truediv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + # TODO: python/mypy#20061 + left.truediv(b) # pyright: ignore[reportArgumentType,reportCallIssue] check(assert_type(left.truediv(i), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.truediv(f), "pd.Series[float]"), pd.Series, np.floating) check( @@ -41,13 +50,15 @@ def test_truediv_py_scalar() -> None: ) if TYPE_CHECKING_INVALID_USAGE: - left.div(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + # TODO: python/mypy#20061 + left.div(b) # pyright: ignore[reportArgumentType,reportCallIssue] check(assert_type(left.div(i), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.div(f), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.div(c), "pd.Series[complex]"), pd.Series, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: - left.rtruediv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + # TODO: python/mypy#20061 + left.rtruediv(b) # pyright: ignore[reportArgumentType,reportCallIssue] check(assert_type(left.rtruediv(i), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.rtruediv(f), "pd.Series[float]"), pd.Series, np.floating) check( @@ -57,7 +68,8 @@ def test_truediv_py_scalar() -> None: ) if TYPE_CHECKING_INVALID_USAGE: - left.rdiv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + # TODO: python/mypy#20061 + left.rdiv(b) # pyright: ignore[reportArgumentType,reportCallIssue] check(assert_type(left.rdiv(i), "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left.rdiv(f), "pd.Series[float]"), pd.Series, np.floating) check( @@ -65,7 +77,7 @@ def test_truediv_py_scalar() -> None: ) -def test_truediv_py_sequence() -> None: +def test_truediv_py_sequence(left: "pd.Series[bool]") -> None: """Test pd.Series[bool] / Python native sequences""" b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] @@ -110,7 +122,7 @@ def test_truediv_py_sequence() -> None: ) -def test_truediv_numpy_array() -> None: +def test_truediv_numpy_array(left: "pd.Series[bool]") -> None: """Test pd.Series[bool] / numpy arrays""" b = np.array([True, False, True], np.bool_) i = np.array([2, 3, 5], np.int64) @@ -171,7 +183,7 @@ def test_truediv_numpy_array() -> None: ) -def test_truediv_pd_index() -> None: +def test_truediv_pd_index(left: "pd.Series[bool]") -> None: """Test pd.Series[bool] / pandas Indexes""" b = pd.Index([True, False, True]) i = pd.Index([2, 3, 5]) @@ -179,13 +191,13 @@ def test_truediv_pd_index() -> None: c = pd.Index([1.1j, 2.2j, 4.1j]) if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left / f, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left / c, "pd.Series[complex]"), pd.Series, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: - _1 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(i / left, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(f / left, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(c / left, "pd.Series[complex]"), pd.Series, np.complexfloating) @@ -225,7 +237,7 @@ def test_truediv_pd_index() -> None: ) -def test_truediv_pd_series() -> None: +def test_truediv_pd_series(left: "pd.Series[bool]") -> None: """Test pd.Series[bool] / pandas Series""" b = pd.Series([True, False, True]) i = pd.Series([2, 3, 5]) @@ -233,13 +245,13 @@ def test_truediv_pd_series() -> None: c = pd.Series([1.1j, 2.2j, 4.1j]) if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left / f, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(left / c, "pd.Series[complex]"), pd.Series, np.complexfloating) if TYPE_CHECKING_INVALID_USAGE: - _1 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(i / left, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(f / left, "pd.Series[float]"), pd.Series, np.floating) check(assert_type(c / left, "pd.Series[complex]"), pd.Series, np.complexfloating) diff --git a/tests/series/arithmetic/complex/test_mul.py b/tests/series/arithmetic/complex/test_mul.py index b997b4d3b..abd2056e5 100644 --- a/tests/series/arithmetic/complex/test_mul.py +++ b/tests/series/arithmetic/complex/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Series[complex]": - """left operand""" + """Left operand""" lo = pd.Series([1j, 2j, 3j]) return check(assert_type(lo, "pd.Series[complex]"), pd.Series, np.complexfloating) diff --git a/tests/series/arithmetic/complex/test_truediv.py b/tests/series/arithmetic/complex/test_truediv.py index 9d564659c..1ad66e307 100644 --- a/tests/series/arithmetic/complex/test_truediv.py +++ b/tests/series/arithmetic/complex/test_truediv.py @@ -1,14 +1,20 @@ import numpy as np from numpy import typing as npt # noqa: F401 import pandas as pd +import pytest from typing_extensions import assert_type from tests import check -left = pd.Series([1j, 2j, 3j]) # left operand +@pytest.fixture +def left() -> "pd.Series[complex]": + """Left operand""" + lo = pd.Series([1j, 2j, 3j]) + return check(assert_type(lo, "pd.Series[complex]"), pd.Series, np.complexfloating) -def test_truediv_py_scalar() -> None: + +def test_truediv_py_scalar(left: "pd.Series[complex]") -> None: """Test pd.Series[complex] / Python native scalars""" b, i, f, c = True, 1, 1.0, 1j @@ -83,7 +89,7 @@ def test_truediv_py_scalar() -> None: ) -def test_truediv_py_sequence() -> None: +def test_truediv_py_sequence(left: "pd.Series[complex]") -> None: """Test pd.Series[complex] / Python native sequences""" b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] @@ -158,7 +164,7 @@ def test_truediv_py_sequence() -> None: ) -def test_truediv_numpy_array() -> None: +def test_truediv_numpy_array(left: "pd.Series[complex]") -> None: """Test pd.Series[complex] / numpy arrays""" b = np.array([True, False, True], np.bool_) i = np.array([2, 3, 5], np.int64) @@ -249,7 +255,7 @@ def test_truediv_numpy_array() -> None: ) -def test_truediv_pd_index() -> None: +def test_truediv_pd_index(left: "pd.Series[complex]") -> None: """Test pd.Series[complex] / pandas Indexes""" b = pd.Index([True, False, True]) i = pd.Index([2, 3, 5]) @@ -327,7 +333,7 @@ def test_truediv_pd_index() -> None: ) -def test_truediv_pd_series() -> None: +def test_truediv_pd_series(left: "pd.Series[complex]") -> None: """Test pd.Series[complex] / pandas Series""" b = pd.Series([True, False, True]) i = pd.Series([2, 3, 5]) diff --git a/tests/series/arithmetic/float/test_mul.py b/tests/series/arithmetic/float/test_mul.py index ae320658b..d83468c06 100644 --- a/tests/series/arithmetic/float/test_mul.py +++ b/tests/series/arithmetic/float/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Series[float]": - """left operand""" + """Left operand""" lo = pd.Series([1.0, 2.0, 3.0]) return check(assert_type(lo, "pd.Series[float]"), pd.Series, np.floating) diff --git a/tests/series/arithmetic/float/test_truediv.py b/tests/series/arithmetic/float/test_truediv.py index 3add54e9e..83c3da2f5 100644 --- a/tests/series/arithmetic/float/test_truediv.py +++ b/tests/series/arithmetic/float/test_truediv.py @@ -1,14 +1,23 @@ import numpy as np from numpy import typing as npt # noqa: F401 import pandas as pd +import pytest from typing_extensions import assert_type -from tests import check +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) -left = pd.Series([1.0, 2.0, 3.0]) # left operand +@pytest.fixture +def left() -> "pd.Series[float]": + """Left operand""" + lo = pd.Series([1.0, 2.0, 3.0]) + return check(assert_type(lo, "pd.Series[float]"), pd.Series, np.floating) -def test_truediv_py_scalar() -> None: + +def test_truediv_py_scalar(left: "pd.Series[float]") -> None: """Test pd.Series[float] / Python native scalars""" b, i, f, c = True, 1, 1.0, 1j @@ -53,7 +62,7 @@ def test_truediv_py_scalar() -> None: ) -def test_truediv_py_sequence() -> None: +def test_truediv_py_sequence(left: "pd.Series[float]") -> None: """Test pd.Series[float] / Python native sequences""" b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] @@ -98,7 +107,7 @@ def test_truediv_py_sequence() -> None: ) -def test_truediv_numpy_array() -> None: +def test_truediv_numpy_array(left: "pd.Series[float]") -> None: """Test pd.Series[float] / numpy arrays""" b = np.array([True, False, True], np.bool_) i = np.array([2, 3, 5], np.int64) @@ -153,7 +162,40 @@ def test_truediv_numpy_array() -> None: ) -def test_truediv_pd_index() -> None: +def test_truediv_pd_scalar(left: "pd.Series[float]") -> None: + """Test pd.Series[float] / pandas scalars""" + s, d = pd.Timestamp(2025, 9, 24), pd.Timedelta(seconds=1) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _01 = left / d # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + + if TYPE_CHECKING_INVALID_USAGE: + _10 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(d / left, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) + + if TYPE_CHECKING_INVALID_USAGE: + left.truediv(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + left.truediv(d) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + + if TYPE_CHECKING_INVALID_USAGE: + left.div(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + left.div(d) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + + if TYPE_CHECKING_INVALID_USAGE: + left.rtruediv(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + check( + assert_type(left.rtruediv(d), "pd.Series[pd.Timedelta]"), + pd.Series, + pd.Timedelta, + ) + + if TYPE_CHECKING_INVALID_USAGE: + left.rdiv(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + check(assert_type(left.rdiv(d), "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) + + +def test_truediv_pd_index(left: "pd.Series[float]") -> None: """Test pd.Series[float] / pandas Indexes""" b = pd.Index([True, False, True]) i = pd.Index([2, 3, 5]) @@ -201,7 +243,7 @@ def test_truediv_pd_index() -> None: ) -def test_truediv_pd_series() -> None: +def test_truediv_pd_series(left: "pd.Series[float]") -> None: """Test pd.Series[float] / pandas Series""" b = pd.Series([True, False, True]) i = pd.Series([2, 3, 5]) diff --git a/tests/series/arithmetic/int/test_mul.py b/tests/series/arithmetic/int/test_mul.py index 030adfc98..e3c1c7f05 100644 --- a/tests/series/arithmetic/int/test_mul.py +++ b/tests/series/arithmetic/int/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Series[int]": - """left operand""" + """Left operand""" lo = pd.Series([1, 2, 3]) return check(assert_type(lo, "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/series/arithmetic/int/test_truediv.py b/tests/series/arithmetic/int/test_truediv.py index f9f665408..757173a3a 100644 --- a/tests/series/arithmetic/int/test_truediv.py +++ b/tests/series/arithmetic/int/test_truediv.py @@ -1,14 +1,23 @@ import numpy as np from numpy import typing as npt # noqa: F401 import pandas as pd +import pytest from typing_extensions import assert_type -from tests import check +from tests import ( + TYPE_CHECKING_INVALID_USAGE, + check, +) -left = pd.Series([1, 2, 3]) # left operand +@pytest.fixture +def left() -> "pd.Series[int]": + """Left operand""" + lo = pd.Series([1, 2, 3]) + return check(assert_type(lo, "pd.Series[int]"), pd.Series, np.integer) -def test_truediv_py_scalar() -> None: + +def test_truediv_py_scalar(left: "pd.Series[int]") -> None: """Test pd.Series[int] / Python native scalars""" b, i, f, c = True, 1, 1.0, 1j @@ -53,7 +62,7 @@ def test_truediv_py_scalar() -> None: ) -def test_truediv_py_sequence() -> None: +def test_truediv_py_sequence(left: "pd.Series[int]") -> None: """Test pd.Series[int] / Python native sequences""" b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] @@ -98,7 +107,7 @@ def test_truediv_py_sequence() -> None: ) -def test_truediv_numpy_array() -> None: +def test_truediv_numpy_array(left: "pd.Series[int]") -> None: """Test pd.Series[int] / numpy arrays""" b = np.array([True, False, True], np.bool_) i = np.array([2, 3, 5], np.int64) @@ -153,7 +162,40 @@ def test_truediv_numpy_array() -> None: ) -def test_truediv_pd_index() -> None: +def test_truediv_pd_scalar(left: "pd.Series[int]") -> None: + """Test pd.Series[int] / pandas scalars""" + s, d = pd.Timestamp(2025, 9, 24), pd.Timedelta(seconds=1) + + if TYPE_CHECKING_INVALID_USAGE: + _00 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _01 = left / d # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + + if TYPE_CHECKING_INVALID_USAGE: + _10 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + check(assert_type(d / left, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) + + if TYPE_CHECKING_INVALID_USAGE: + left.truediv(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + left.truediv(d) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + + if TYPE_CHECKING_INVALID_USAGE: + left.div(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + left.div(d) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + + if TYPE_CHECKING_INVALID_USAGE: + left.rtruediv(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + check( + assert_type(left.rtruediv(d), "pd.Series[pd.Timedelta]"), + pd.Series, + pd.Timedelta, + ) + + if TYPE_CHECKING_INVALID_USAGE: + left.rdiv(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue] + check(assert_type(left.rdiv(d), "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) + + +def test_truediv_pd_index(left: "pd.Series[int]") -> None: """Test pd.Series[int] / pandas Indexes""" b = pd.Index([True, False, True]) i = pd.Index([2, 3, 5]) @@ -201,7 +243,7 @@ def test_truediv_pd_index() -> None: ) -def test_truediv_pd_series() -> None: +def test_truediv_pd_series(left: "pd.Series[int]") -> None: """Test pd.Series[int] / pandas Series""" b = pd.Series([True, False, True]) i = pd.Series([2, 3, 5]) diff --git a/tests/series/arithmetic/str/test_mul.py b/tests/series/arithmetic/str/test_mul.py index 6d5655bde..ef272db26 100644 --- a/tests/series/arithmetic/str/test_mul.py +++ b/tests/series/arithmetic/str/test_mul.py @@ -21,7 +21,7 @@ @pytest.fixture def left() -> "pd.Series[str]": - """left operand""" + """Left operand""" lo = pd.Series(["1", "2", "3"]) return check(assert_type(lo, "pd.Series[str]"), pd.Series, str) diff --git a/tests/series/arithmetic/test_mul.py b/tests/series/arithmetic/test_mul.py index 4d1b3aaa3..0c6b70fc9 100644 --- a/tests/series/arithmetic/test_mul.py +++ b/tests/series/arithmetic/test_mul.py @@ -13,7 +13,7 @@ @pytest.fixture def left_i() -> pd.Series: - """left operand""" + """Left operand""" lo = pd.DataFrame({"a": [1, 2, 3]})["a"] return check(assert_type(lo, pd.Series), pd.Series) diff --git a/tests/series/arithmetic/test_truediv.py b/tests/series/arithmetic/test_truediv.py index 9baa2c49b..d0802d1c2 100644 --- a/tests/series/arithmetic/test_truediv.py +++ b/tests/series/arithmetic/test_truediv.py @@ -3,18 +3,23 @@ import numpy as np import pandas as pd +import pytest from typing_extensions import assert_type from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, ) -left_i = pd.DataFrame({"a": [1, 2, 3]})["a"] # left operand +@pytest.fixture +def left_i() -> pd.Series: + """Left operand""" + lo = pd.DataFrame({"a": [1, 2, 3]})["a"] + return check(assert_type(lo, pd.Series), pd.Series, np.integer) -def test_truediv_py_scalar() -> None: + +def test_truediv_py_scalar(left_i: pd.Series) -> None: """Test pd.Series[Any] (int) / Python native scalars""" b, i, f, c = True, 1, 1.0, 1j @@ -49,7 +54,7 @@ def test_truediv_py_scalar() -> None: check(assert_type(left_i.rdiv(c), pd.Series), pd.Series) -def test_truediv_py_sequence() -> None: +def test_truediv_py_sequence(left_i: pd.Series) -> None: """Test pd.Series[Any] (int) / Python native sequences""" b, i, f, c = [True, False, True], [2, 3, 5], [1.0, 2.0, 3.0], [1j, 1j, 4j] @@ -84,7 +89,7 @@ def test_truediv_py_sequence() -> None: check(assert_type(left_i.rdiv(c), pd.Series), pd.Series) -def test_truediv_numpy_array() -> None: +def test_truediv_numpy_array(left_i: pd.Series) -> None: """Test pd.Series[Any] (int) / numpy arrays""" b = np.array([True, False, True], np.bool_) i = np.array([2, 3, 5], np.int64) @@ -138,7 +143,7 @@ def test_truediv_numpy_array() -> None: check(assert_type(left_i.rdiv(c), pd.Series), pd.Series) -def test_truediv_pd_index() -> None: +def test_truediv_pd_index(left_i: pd.Series) -> None: """Test pd.Series[Any] (int) / pandas Indexes""" a = pd.MultiIndex.from_tuples([(1,), (2,), (3,)]).levels[0] b = pd.Index([True, False, True]) @@ -183,7 +188,7 @@ def test_truediv_pd_index() -> None: check(assert_type(left_i.rdiv(c), pd.Series), pd.Series) -def test_truediv_pd_series() -> None: +def test_truediv_pd_series(left_i: pd.Series) -> None: """Test pd.Series[Any] (int) / pandas Series""" a = pd.DataFrame({"a": [1, 2, 3]})["a"] b = pd.Series([True, False, True]) @@ -251,19 +256,17 @@ def test_truediv_path(tmp_path: Path) -> None: Also GH 682.""" fnames = pd.Series(["a.png", "b.gz", "c.txt"]) - if PD_LTE_23: - # Bug in 3.0 https://github.com/pandas-dev/pandas/issues/61940 (pyarrow.lib.ArrowInvalid) - check(assert_type(fnames / tmp_path, pd.Series), pd.Series, Path) - check(assert_type(tmp_path / fnames, pd.Series), pd.Series, Path) + check(assert_type(fnames / tmp_path, pd.Series), pd.Series, Path) + check(assert_type(tmp_path / fnames, pd.Series), pd.Series, Path) - check(assert_type(fnames.truediv(tmp_path), pd.Series), pd.Series, Path) - check(assert_type(fnames.div(tmp_path), pd.Series), pd.Series, Path) + check(assert_type(fnames.truediv(tmp_path), pd.Series), pd.Series, Path) + check(assert_type(fnames.div(tmp_path), pd.Series), pd.Series, Path) - check(assert_type(fnames.rtruediv(tmp_path), pd.Series), pd.Series, Path) - check(assert_type(fnames.rdiv(tmp_path), pd.Series), pd.Series, Path) + check(assert_type(fnames.rtruediv(tmp_path), pd.Series), pd.Series, Path) + check(assert_type(fnames.rdiv(tmp_path), pd.Series), pd.Series, Path) -def test_truediv_str_py_str() -> None: +def test_truediv_str_py_str(left_i: pd.Series) -> None: """Test pd.Series[Any] (int) / Python str""" s = "abc" diff --git a/tests/series/arithmetic/timedelta/test_mul.py b/tests/series/arithmetic/timedelta/test_mul.py index 0608e3e4a..2add38111 100644 --- a/tests/series/arithmetic/timedelta/test_mul.py +++ b/tests/series/arithmetic/timedelta/test_mul.py @@ -15,7 +15,7 @@ @pytest.fixture def left() -> "pd.Series[pd.Timedelta]": - """left operand""" + """Left operand""" lo = pd.Series([pd.Timedelta(1, "s")]) # left operand return check(assert_type(lo, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) diff --git a/tests/series/arithmetic/timedelta/test_truediv.py b/tests/series/arithmetic/timedelta/test_truediv.py index 1c8a59864..da7fad64f 100644 --- a/tests/series/arithmetic/timedelta/test_truediv.py +++ b/tests/series/arithmetic/timedelta/test_truediv.py @@ -26,20 +26,20 @@ def test_truediv_py_scalar() -> None: s, d = datetime(2025, 9, 24), timedelta(seconds=1) if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) check(assert_type(left / f, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: - _1 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _2 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / d, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: - _3 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _4 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _5 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _6 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _7 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(d / left, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: @@ -87,20 +87,20 @@ def test_truediv_py_sequence() -> None: s, d = [datetime(2025, 9, 24)], [timedelta(seconds=1)] if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) check(assert_type(left / f, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: - _1 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _2 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / d, "pd.Series[float]"), pd.Series, float) if TYPE_CHECKING_INVALID_USAGE: - _3 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _4 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _5 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _6 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _7 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(d / left, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: @@ -248,20 +248,20 @@ def test_truediv_pd_index() -> None: s, d = pd.Index([datetime(2025, 9, 24)]), pd.Index([timedelta(seconds=1)]) if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) check(assert_type(left / f, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: - _1 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _2 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / d, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: - _3 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _4 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _5 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _6 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _7 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(d / left, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: @@ -312,20 +312,20 @@ def test_truediv_pd_series() -> None: s, d = pd.Series([datetime(2025, 9, 24)]), pd.Series([timedelta(seconds=1)]) if TYPE_CHECKING_INVALID_USAGE: - _0 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _00 = left / b # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / i, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) check(assert_type(left / f, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) if TYPE_CHECKING_INVALID_USAGE: - _1 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _2 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _03 = left / c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _04 = left / s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(left / d, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: - _3 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _4 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _5 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _6 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] - _7 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _10 = b / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _11 = i / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _12 = f / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _13 = c / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] + _14 = s / left # type: ignore[operator] # pyright: ignore[reportOperatorIssue] check(assert_type(d / left, "pd.Series[float]"), pd.Series, np.floating) if TYPE_CHECKING_INVALID_USAGE: