diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index b6111db8..8da1c6ae 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -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]: ... @@ -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], @@ -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, diff --git a/tests/test_series.py b/tests/test_series.py index efd368f8..42de32de 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -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, + )