11from datetime import timedelta
22from typing import (
33 ClassVar ,
4+ Literal ,
45 Type ,
56 TypeVar ,
67 overload ,
78)
89
910import numpy as np
10- import numpy .typing as npt
1111
1212from pandas ._libs .tslibs import (
1313 NaTType ,
1414 Tick ,
1515)
16+ from pandas ._typing import npt
1617
18+ # This should be kept consistent with the keys in the dict timedelta_abbrevs
19+ # in pandas/_libs/tslibs/timedeltas.pyx
20+ UnitChoices = Literal [
21+ "Y" ,
22+ "y" ,
23+ "M" ,
24+ "W" ,
25+ "w" ,
26+ "D" ,
27+ "d" ,
28+ "days" ,
29+ "day" ,
30+ "hours" ,
31+ "hour" ,
32+ "hr" ,
33+ "h" ,
34+ "m" ,
35+ "minute" ,
36+ "min" ,
37+ "minutes" ,
38+ "t" ,
39+ "s" ,
40+ "seconds" ,
41+ "sec" ,
42+ "second" ,
43+ "ms" ,
44+ "milliseconds" ,
45+ "millisecond" ,
46+ "milli" ,
47+ "millis" ,
48+ "l" ,
49+ "us" ,
50+ "microseconds" ,
51+ "microsecond" ,
52+ "µs" ,
53+ "micro" ,
54+ "micros" ,
55+ "u" ,
56+ "ns" ,
57+ "nanoseconds" ,
58+ "nano" ,
59+ "nanos" ,
60+ "nanosecond" ,
61+ "n" ,
62+ ]
1763_S = TypeVar ("_S" , bound = timedelta )
1864
1965def ints_to_pytimedelta (
@@ -25,7 +71,7 @@ def array_to_timedelta64(
2571 unit : str | None = ...,
2672 errors : str = ...,
2773) -> np .ndarray : ... # np.ndarray[m8ns]
28- def parse_timedelta_unit (unit : str | None ) -> str : ...
74+ def parse_timedelta_unit (unit : str | None ) -> UnitChoices : ...
2975def delta_to_nanoseconds (delta : np .timedelta64 | timedelta | Tick ) -> int : ...
3076
3177class Timedelta (timedelta ):
@@ -59,20 +105,20 @@ class Timedelta(timedelta):
59105 def ceil (self : _S , freq : str ) -> _S : ...
60106 @property
61107 def resolution_string (self ) -> str : ...
62- def __add__ (self , other : timedelta ) -> timedelta : ...
63- def __radd__ (self , other : timedelta ) -> timedelta : ...
64- def __sub__ (self , other : timedelta ) -> timedelta : ...
65- def __rsub__ (self , other : timedelta ) -> timedelta : ...
66- def __neg__ (self ) -> timedelta : ...
67- def __pos__ (self ) -> timedelta : ...
68- def __abs__ (self ) -> timedelta : ...
69- def __mul__ (self , other : float ) -> timedelta : ...
70- def __rmul__ (self , other : float ) -> timedelta : ...
108+ def __add__ (self , other : timedelta ) -> Timedelta : ...
109+ def __radd__ (self , other : timedelta ) -> Timedelta : ...
110+ def __sub__ (self , other : timedelta ) -> Timedelta : ...
111+ def __rsub__ (self , other : timedelta ) -> Timedelta : ...
112+ def __neg__ (self ) -> Timedelta : ...
113+ def __pos__ (self ) -> Timedelta : ...
114+ def __abs__ (self ) -> Timedelta : ...
115+ def __mul__ (self , other : float ) -> Timedelta : ...
116+ def __rmul__ (self , other : float ) -> Timedelta : ...
71117 # error: Signature of "__floordiv__" incompatible with supertype "timedelta"
72118 @overload # type: ignore[override]
73119 def __floordiv__ (self , other : timedelta ) -> int : ...
74120 @overload
75- def __floordiv__ (self , other : int | float ) -> timedelta : ...
121+ def __floordiv__ (self , other : int | float ) -> Timedelta : ...
76122 @overload
77123 def __floordiv__ (
78124 self , other : npt .NDArray [np .timedelta64 ]
@@ -90,11 +136,13 @@ class Timedelta(timedelta):
90136 @overload
91137 def __truediv__ (self , other : timedelta ) -> float : ...
92138 @overload
93- def __truediv__ (self , other : float ) -> timedelta : ...
94- def __mod__ (self , other : timedelta ) -> timedelta : ...
95- def __divmod__ (self , other : timedelta ) -> tuple [int , timedelta ]: ...
139+ def __truediv__ (self , other : float ) -> Timedelta : ...
140+ def __mod__ (self , other : timedelta ) -> Timedelta : ...
141+ def __divmod__ (self , other : timedelta ) -> tuple [int , Timedelta ]: ...
96142 def __le__ (self , other : timedelta ) -> bool : ...
97143 def __lt__ (self , other : timedelta ) -> bool : ...
98144 def __ge__ (self , other : timedelta ) -> bool : ...
99145 def __gt__ (self , other : timedelta ) -> bool : ...
100146 def __hash__ (self ) -> int : ...
147+ def isoformat (self ) -> str : ...
148+ def to_numpy (self ) -> np .timedelta64 : ...
0 commit comments