1
1
from datetime import timedelta
2
2
from typing import (
3
3
ClassVar ,
4
+ Literal ,
4
5
Type ,
5
6
TypeVar ,
6
7
overload ,
7
8
)
8
9
9
10
import numpy as np
10
- import numpy .typing as npt
11
11
12
12
from pandas ._libs .tslibs import (
13
13
NaTType ,
14
14
Tick ,
15
15
)
16
+ from pandas ._typing import npt
16
17
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
+ ]
17
63
_S = TypeVar ("_S" , bound = timedelta )
18
64
19
65
def ints_to_pytimedelta (
@@ -25,7 +71,7 @@ def array_to_timedelta64(
25
71
unit : str | None = ...,
26
72
errors : str = ...,
27
73
) -> np .ndarray : ... # np.ndarray[m8ns]
28
- def parse_timedelta_unit (unit : str | None ) -> str : ...
74
+ def parse_timedelta_unit (unit : str | None ) -> UnitChoices : ...
29
75
def delta_to_nanoseconds (delta : np .timedelta64 | timedelta | Tick ) -> int : ...
30
76
31
77
class Timedelta (timedelta ):
@@ -59,20 +105,20 @@ class Timedelta(timedelta):
59
105
def ceil (self : _S , freq : str ) -> _S : ...
60
106
@property
61
107
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 : ...
71
117
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
72
118
@overload # type: ignore[override]
73
119
def __floordiv__ (self , other : timedelta ) -> int : ...
74
120
@overload
75
- def __floordiv__ (self , other : int | float ) -> timedelta : ...
121
+ def __floordiv__ (self , other : int | float ) -> Timedelta : ...
76
122
@overload
77
123
def __floordiv__ (
78
124
self , other : npt .NDArray [np .timedelta64 ]
@@ -90,11 +136,13 @@ class Timedelta(timedelta):
90
136
@overload
91
137
def __truediv__ (self , other : timedelta ) -> float : ...
92
138
@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 ]: ...
96
142
def __le__ (self , other : timedelta ) -> bool : ...
97
143
def __lt__ (self , other : timedelta ) -> bool : ...
98
144
def __ge__ (self , other : timedelta ) -> bool : ...
99
145
def __gt__ (self , other : timedelta ) -> bool : ...
100
146
def __hash__ (self ) -> int : ...
147
+ def isoformat (self ) -> str : ...
148
+ def to_numpy (self ) -> np .timedelta64 : ...
0 commit comments