File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed
pandas-stubs/_libs/tslibs Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ from pandas._libs.tslibs import (
3030from pandas ._libs .tslibs .period import Period
3131from pandas ._libs .tslibs .timestamps import Timestamp
3232from pandas ._typing import (
33+ Just ,
3334 ShapeT ,
3435 TimeUnit ,
3536 np_1darray ,
@@ -209,13 +210,13 @@ class Timedelta(timedelta):
209210 def __abs__ (self ) -> Self : ...
210211 # Override due to more types supported than timedelta
211212 @overload # type: ignore[override]
212- def __mul__ (self , other : float ) -> Self : ...
213+ def __mul__ (self , other : Just [ float ] | Just [ int ] ) -> Self : ...
213214 @overload
214215 def __mul__ (
215216 self , other : np_ndarray [ShapeT , np .bool_ | np .integer | np .floating ]
216217 ) -> np_ndarray [ShapeT , np .timedelta64 ]: ...
217218 @overload
218- def __rmul__ (self , other : float ) -> Self : ...
219+ def __rmul__ (self , other : Just [ float ] | Just [ int ] ) -> Self : ...
219220 @overload
220221 def __rmul__ (
221222 self , other : np_ndarray [ShapeT , np .bool_ | np .integer | np .floating ]
Original file line number Diff line number Diff line change @@ -2063,5 +2063,4 @@ def test_period_methods() -> None:
20632063
20642064def test_nattype_hashable () -> None :
20652065 # GH 827
2066- _aset = {pd .NaT }
20672066 check (assert_type (pd .NaT .__hash__ (), int ), int )
Original file line number Diff line number Diff line change 1+ """Test file for arithmetic method on Timedelta objects."""
2+
3+ import pandas as pd
4+ from typing_extensions import assert_type
5+
6+ from tests import (
7+ TYPE_CHECKING_INVALID_USAGE ,
8+ check ,
9+ )
10+
11+
12+ def test_mul () -> None :
13+ """Test checking that pd.Timedelta * int / float."""
14+ a = pd .Timedelta ("1 day" )
15+ b = True
16+ c = 1.0
17+ d = 5
18+ e = 1 + 3.0j
19+
20+ check (assert_type (a * c , pd .Timedelta ), pd .Timedelta )
21+ check (assert_type (c * a , pd .Timedelta ), pd .Timedelta )
22+ check (assert_type (a * d , pd .Timedelta ), pd .Timedelta )
23+ check (assert_type (d * a , pd .Timedelta ), pd .Timedelta )
24+
25+ if TYPE_CHECKING_INVALID_USAGE :
26+ # pd.Timedelta * bool is not allowed, see GH1418
27+ _0 = a * b # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
28+ _1 = b * a # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
29+ _2 = a * e # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
30+ _3 = e * a # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
You can’t perform that action at this time.
0 commit comments