diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 0249bb5c8..e451c8efc 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1,5 +1,6 @@ from datetime import ( date, + datetime, time, ) from typing import ( @@ -1218,7 +1219,9 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): def __rtruediv__(self, other: num | _ListLike | Series[S1]) -> Series: ... def __rxor__(self, other: num | _ListLike | Series[S1]) -> Series[_bool]: ... @overload - def __sub__(self, other: Timestamp | TimestampSeries) -> TimedeltaSeries: ... + def __sub__( + self, other: Timestamp | datetime | TimestampSeries + ) -> TimedeltaSeries: ... @overload def __sub__( self, other: Timedelta | TimedeltaSeries | TimedeltaIndex diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 8e5a39fea..ff9d86bc1 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -120,8 +120,6 @@ def test_timedelta_series_arithmetic() -> None: def test_timestamp_timedelta_series_arithmetic() -> None: - ts = pd.Timestamp("2022-03-05") - s1 = pd.Series(["2022-03-05", "2022-03-06"]) ts1 = pd.to_datetime(pd.Series(["2022-03-05", "2022-03-06"])) assert isinstance(ts1.iloc[0], pd.Timestamp) td1 = pd.to_timedelta([2, 3], "seconds") @@ -141,6 +139,13 @@ def test_timestamp_timedelta_series_arithmetic() -> None: r6 = r1 * 4 check(assert_type(r6, "TimedeltaSeries"), pd.Series, pd.Timedelta) + tsp1 = pd.Timestamp("2022-03-05") + dt1 = dt.datetime(2022, 9, 1, 12, 5, 30) + r7 = ts1 - tsp1 + check(assert_type(r7, "TimedeltaSeries"), pd.Series, pd.Timedelta) + r8 = ts1 - dt1 + check(assert_type(r8, "TimedeltaSeries"), pd.Series, pd.Timedelta) + def test_timestamp_dateoffset_arithmetic() -> None: ts = pd.Timestamp("2022-03-18")