Skip to content
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

748 series operator timedelta #924

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 27 additions & 4 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,11 @@ class Series(IndexOpsMixin[S1], NDFrame):
def __rdivmod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __rfloordiv__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
def __rmod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
@overload
def __rmul__(
self, other: timedelta | Timedelta | TimedeltaSeries | np.timedelta64
) -> TimedeltaSeries: ...
@overload
def __rmul__(self, other: num | _ListLike | Series) -> Series: ...
def __rnatmul__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
def __rpow__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
Expand Down Expand Up @@ -1794,13 +1799,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[S1]: ...
@overload
def mul(
self,
other: num | _ListLike | Series[S1],
other: timedelta | Timedelta | TimedeltaSeries | np.timedelta64,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series[S1]: ...
) -> TimedeltaSeries: ...
@overload
def mul(
self,
other: num | _ListLike | Series,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex | None = ...,
) -> Series: ...
def multiply(
self,
other: num | _ListLike | Series[S1],
Expand Down Expand Up @@ -1869,13 +1883,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series[S1]: ...
@overload
def rmul(
self,
other: Series[S1] | Scalar,
other: timedelta | Timedelta | TimedeltaSeries | np.timedelta64,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series[S1]: ...
) -> TimedeltaSeries: ...
@overload
def rmul(
self,
other: num | _ListLike | Series,
level: Level | None = ...,
fill_value: float | None = ...,
axis: AxisIndex = ...,
) -> Series: ...
@overload
def rolling(
self,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3214,3 +3214,28 @@ def test_diff_never3() -> None:
if TYPE_CHECKING_INVALID_USAGE:
# str -> TypeError: unsupported operand type(s) for -: 'str' and 'str'
assert_never(pd.Series(["a", "b"]).diff())


def test_operator_constistency() -> None:
# created for #748
s = pd.Series([1, 2, 3])
check(
assert_type(s * np.timedelta64(1, "s"), "TimedeltaSeries"),
pd.Series,
pd.Timedelta,
)
check(
assert_type(np.timedelta64(1, "s") * s, "TimedeltaSeries"),
pd.Series,
pd.Timedelta,
)
check(
assert_type(s.mul(np.timedelta64(1, "s")), "TimedeltaSeries"),
pd.Series,
pd.Timedelta,
)
check(
assert_type(s.rmul(np.timedelta64(1, "s")), "TimedeltaSeries"),
pd.Series,
pd.Timedelta,
)
Loading