Skip to content
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
5 changes: 3 additions & 2 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ from pandas._libs.tslibs import (
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
Just,
ShapeT,
TimeUnit,
np_1darray,
Expand Down Expand Up @@ -209,13 +210,13 @@ class Timedelta(timedelta):
def __abs__(self) -> Self: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __mul__(self, other: float) -> Self: ...
def __mul__(self, other: Just[float] | Just[int]) -> Self: ...
@overload
def __mul__(
self, other: np_ndarray[ShapeT, np.bool_ | np.integer | np.floating]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __rmul__(self, other: float) -> Self: ...
def __rmul__(self, other: Just[float] | Just[int]) -> Self: ...
@overload
def __rmul__(
self, other: np_ndarray[ShapeT, np.bool_ | np.integer | np.floating]
Expand Down
1 change: 0 additions & 1 deletion tests/scalars/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,5 +2063,4 @@ def test_period_methods() -> None:

def test_nattype_hashable() -> None:
# GH 827
_aset = {pd.NaT}
check(assert_type(pd.NaT.__hash__(), int), int)
Empty file.
30 changes: 30 additions & 0 deletions tests/scalars/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Test file for arithmetic method on Timedelta objects."""

import pandas as pd
from typing_extensions import assert_type

from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
)


def test_mul() -> None:
"""Test checking that pd.Timedelta * int / float."""
a = pd.Timedelta("1 day")
b = True
c = 1.0
d = 5
e = 1 + 3.0j

check(assert_type(a * c, pd.Timedelta), pd.Timedelta)
check(assert_type(c * a, pd.Timedelta), pd.Timedelta)
check(assert_type(a * d, pd.Timedelta), pd.Timedelta)
check(assert_type(d * a, pd.Timedelta), pd.Timedelta)

if TYPE_CHECKING_INVALID_USAGE:
# pd.Timedelta * bool is not allowed, see GH1418
_0 = a * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_1 = b * a # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_2 = a * e # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
_3 = e * a # type: ignore[operator] # pyright: ignore[reportOperatorIssue]