diff --git a/pandas-stubs/_libs/interval.pyi b/pandas-stubs/_libs/interval.pyi index 47ec373c6..3507d3b13 100644 --- a/pandas-stubs/_libs/interval.pyi +++ b/pandas-stubs/_libs/interval.pyi @@ -13,6 +13,10 @@ from pandas import ( Timedelta, Timestamp, ) +from pandas.core.series import ( + TimedeltaSeries, + TimestampSeries, +) from pandas._typing import ( IntervalClosedType, @@ -170,7 +174,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]): @overload def __gt__( self, - other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta], + other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries, ) -> Series[bool]: ... @overload def __lt__(self, other: Interval[_OrderableT]) -> bool: ... @@ -178,7 +182,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]): def __lt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... @overload def __lt__( - self, other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta] + self, + other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries, ) -> Series[bool]: ... @overload def __ge__(self, other: Interval[_OrderableT]) -> bool: ... @@ -186,7 +191,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]): def __ge__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... @overload def __ge__( - self, other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta] + self, + other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries, ) -> Series[bool]: ... @overload def __le__(self, other: Interval[_OrderableT]) -> bool: ... diff --git a/pandas-stubs/_libs/tslibs/period.pyi b/pandas-stubs/_libs/tslibs/period.pyi index bd4cd53f6..b6723d851 100644 --- a/pandas-stubs/_libs/tslibs/period.pyi +++ b/pandas-stubs/_libs/tslibs/period.pyi @@ -101,7 +101,7 @@ class Period(PeriodMixin): @overload def __eq__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc] @overload - def __eq__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... # type: ignore[misc] + def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[misc] @overload def __eq__(self, other: object) -> Literal[False]: ... @overload @@ -109,25 +109,25 @@ class Period(PeriodMixin): @overload def __ge__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __ge__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __ge__(self, other: PeriodSeries) -> Series[bool]: ... @overload def __gt__(self, other: Period) -> bool: ... @overload def __gt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __gt__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __gt__(self, other: PeriodSeries) -> Series[bool]: ... @overload def __le__(self, other: Period) -> bool: ... @overload def __le__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __le__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __le__(self, other: PeriodSeries) -> Series[bool]: ... @overload def __lt__(self, other: Period) -> bool: ... @overload def __lt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __lt__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __lt__(self, other: PeriodSeries) -> Series[bool]: ... # ignore[misc] here because we know all other comparisons # are False, so we use Literal[False] @overload @@ -135,7 +135,7 @@ class Period(PeriodMixin): @overload def __ne__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc] @overload - def __ne__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... # type: ignore[misc] + def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[misc] @overload def __ne__(self, other: object) -> Literal[True]: ... # Ignored due to indecipherable error from mypy: diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi index 79211051b..f70709292 100644 --- a/pandas-stubs/_libs/tslibs/timedeltas.pyi +++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi @@ -169,12 +169,11 @@ class Timedelta(timedelta): def __add__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ... @overload def __add__( - self, other: TimedeltaSeries | Series[pd.Timedelta] + self, + other: TimedeltaSeries, ) -> TimedeltaSeries: ... @overload - def __add__( - self, other: Series[Timestamp] | TimestampSeries - ) -> TimestampSeries: ... + def __add__(self, other: TimestampSeries) -> TimestampSeries: ... @overload def __radd__(self, other: np.datetime64) -> Timestamp: ... @overload @@ -277,9 +276,7 @@ class Timedelta(timedelta): @overload def __floordiv__(self, other: Series[float]) -> TimedeltaSeries: ... @overload - def __floordiv__( - self, other: Series[Timedelta] | TimedeltaSeries - ) -> Series[int]: ... + def __floordiv__(self, other: TimedeltaSeries) -> Series[int]: ... @overload def __floordiv__(self, other: NaTType | None) -> float: ... @overload @@ -300,9 +297,7 @@ class Timedelta(timedelta): self, other: npt.NDArray[np.integer] | npt.NDArray[np.floating] ) -> npt.NDArray[np.timedelta64]: ... @overload - def __truediv__( - self, other: Series[Timedelta] | TimedeltaSeries - ) -> Series[float]: ... + def __truediv__(self, other: TimedeltaSeries) -> Series[float]: ... @overload def __truediv__(self, other: Series[int]) -> TimedeltaSeries: ... @overload @@ -347,7 +342,7 @@ class Timedelta(timedelta): ) -> npt.NDArray[np.timedelta64]: ... @overload def __mod__( - self, other: Series[int] | Series[float] | Series[Timedelta] | TimedeltaSeries + self, other: Series[int] | Series[float] | TimedeltaSeries ) -> TimedeltaSeries: ... def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ... # Mypy complains Forward operator "" is not callable, so ignore misc diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 3f5d32adf..d00b7dabc 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -159,25 +159,25 @@ class Timestamp(datetime): @overload def __le__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ... @overload - def __le__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... + def __le__(self, other: TimestampSeries) -> Series[bool]: ... @overload # type: ignore[override] def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] @overload def __lt__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ... @overload - def __lt__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... + def __lt__(self, other: TimestampSeries) -> Series[bool]: ... @overload # type: ignore[override] def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] @overload def __ge__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ... @overload - def __ge__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... + def __ge__(self, other: TimestampSeries) -> Series[bool]: ... @overload # type: ignore[override] def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] @overload def __gt__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ... @overload - def __gt__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... + def __gt__(self, other: TimestampSeries) -> Series[bool]: ... # error: Signature of "__add__" incompatible with supertype "date"/"datetime" @overload # type: ignore[override] def __add__( @@ -188,9 +188,7 @@ class Timestamp(datetime): self: _DatetimeT, other: timedelta | np.timedelta64 | Tick ) -> _DatetimeT: ... @overload - def __add__( - self, other: TimedeltaSeries | Series[Timedelta] - ) -> TimestampSeries: ... + def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ... @overload def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ... @overload @@ -219,7 +217,7 @@ class Timestamp(datetime): @overload def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload] @overload - def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... # type: ignore[misc] + def __eq__(self, other: TimestampSeries | Series[np.datetime64]) -> Series[bool]: ... # type: ignore[misc] @overload def __eq__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc] @overload @@ -227,7 +225,7 @@ class Timestamp(datetime): @overload def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload] @overload - def __ne__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... # type: ignore[misc] + def __ne__(self, other: TimestampSeries | Series[np.datetime64]) -> Series[bool]: ... # type: ignore[misc] @overload def __ne__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc] @overload diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 0bb08be20..ae760f9e7 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -197,9 +197,7 @@ S1 = TypeVar( str, bytes, datetime.date, - datetime.datetime, datetime.time, - datetime.timedelta, bool, int, float, diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index a3d3aa143..19ee6efe8 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -56,14 +56,12 @@ _EdgesFloat: TypeAlias = Union[ _EdgesTimestamp: TypeAlias = Union[ Sequence[DatetimeLike], npt.NDArray[np.datetime64], - pd.Series[pd.Timestamp], TimestampSeries, pd.DatetimeIndex, ] _EdgesTimedelta: TypeAlias = Union[ Sequence[pd.Timedelta], npt.NDArray[np.timedelta64], - pd.Series[pd.Timedelta], TimedeltaSeries, pd.TimedeltaIndex, ] diff --git a/tests/test_scalars.py b/tests/test_scalars.py index 87143e2a6..7814e245d 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -1256,9 +1256,7 @@ def test_timestamp_cmp() -> None: c_dt_datetime = dt.datetime(year=2000, month=1, day=1) c_datetimeindex = pd.DatetimeIndex(["2000-1-1"]) c_np_ndarray_dt64 = np_dt64_arr - # Typing provided since there is no way to get a Series[Timestamp], - # which is a different type from a TimestampSeries - c_series_dt64: pd.Series[pd.Timestamp] = pd.Series( + c_series_dt64: pd.Series[np.datetime64] = pd.Series( [1, 2, 3], dtype="datetime64[ns]" ) c_series_timestamp = pd.Series(pd.DatetimeIndex(["2000-1-1"]))