Skip to content

make sub of timedelta work #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,16 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
@overload
def __rxor__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc]
@overload
def __sub__(
self: Series[Timestamp],
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
) -> TimestampSeries: ...
@overload
def __sub__(
self: Series[Timedelta],
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
) -> TimedeltaSeries: ...
@overload
def __sub__(
self, other: Timestamp | datetime | TimestampSeries
) -> TimedeltaSeries: ...
Expand Down
9 changes: 8 additions & 1 deletion tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,14 @@ def test_timedelta64_and_arithmatic_operator() -> None:
s1 = pd.Series(data=pd.date_range("1/1/2020", "2/1/2020"))
s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021"))
s3 = s2 - s1
# https://github.com/pandas-dev/pandas/issues/54059 needs to be fixed
check(assert_type(s3, "TimedeltaSeries"), pd.Series, pd.Timedelta)
td1 = pd.Timedelta(1, "D")
check(assert_type(s2 - td1, "TimestampSeries"), pd.Series, pd.Timestamp)
# GH 758
s4 = s1.astype(object)
check(assert_type(s4 - td1, "TimestampSeries"), pd.Series, pd.Timestamp)

# https://github.com/pandas-dev/pandas/issues/54059 says this is invalid
if PD_LTE_20:
td = np.timedelta64(1, "M")
check(assert_type((s1 - td), "TimestampSeries"), pd.Series, pd.Timestamp)
Expand Down