@@ -13,28 +13,24 @@ from typing import (
1313)
1414
1515import numpy as np
16- import pandas as pd
17- from pandas import (
18- DatetimeIndex ,
19- Index ,
20- PeriodIndex ,
21- Series ,
22- TimedeltaIndex ,
23- )
16+ from numpy import typing as npt
17+ from pandas .core .indexes .base import Index
18+ from pandas .core .indexes .datetimes import DatetimeIndex
19+ from pandas .core .indexes .period import PeriodIndex
20+ from pandas .core .indexes .timedeltas import TimedeltaIndex
21+ from pandas .core .series import Series
2422from typing_extensions import Self
2523
26- from pandas ._libs .tslibs import (
27- BaseOffset ,
28- NaTType ,
29- )
24+ from pandas ._libs .tslibs import NaTType
3025from pandas ._libs .tslibs .period import Period
3126from pandas ._libs .tslibs .timestamps import Timestamp
3227from pandas ._typing import (
28+ Frequency ,
29+ Just ,
3330 ShapeT ,
3431 TimeUnit ,
3532 np_1darray ,
3633 np_ndarray ,
37- npt ,
3834)
3935
4036class Components (NamedTuple ):
@@ -130,10 +126,10 @@ class Timedelta(timedelta):
130126 def to_timedelta64 (self ) -> np .timedelta64 : ...
131127 @property
132128 def asm8 (self ) -> np .timedelta64 : ...
133- # TODO: round/floor/ceil could return NaT?
134- def round (self , freq : str | BaseOffset ) -> Self : ...
135- def floor (self , freq : str | BaseOffset ) -> Self : ...
136- def ceil (self , freq : str | BaseOffset ) -> Self : ...
129+ # TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
130+ def round (self , freq : Frequency ) -> Self : ...
131+ def floor (self , freq : Frequency ) -> Self : ...
132+ def ceil (self , freq : Frequency ) -> Self : ...
137133 @property
138134 def resolution_string (self ) -> str : ...
139135 # Override due to more types supported than timedelta
@@ -173,17 +169,17 @@ class Timedelta(timedelta):
173169 ) -> np_ndarray [ShapeT , np .datetime64 ]: ...
174170 # Override due to more types supported than timedelta
175171 @overload # type: ignore[override]
176- def __sub__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> Self : ...
172+ def __sub__ (self , other : timedelta | np .timedelta64 | Self ) -> Self : ...
177173 @overload
178174 def __sub__ (self , other : NaTType ) -> NaTType : ...
179175 @overload
180176 def __sub__ (
181177 self , other : np_ndarray [ShapeT , np .timedelta64 ]
182178 ) -> np_ndarray [ShapeT , np .timedelta64 ]: ...
183179 @overload
184- def __sub__ (self , other : pd . TimedeltaIndex ) -> TimedeltaIndex : ...
180+ def __sub__ (self , other : TimedeltaIndex ) -> TimedeltaIndex : ...
185181 @overload
186- def __rsub__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> Self : ...
182+ def __rsub__ (self , other : timedelta | np .timedelta64 | Self ) -> Self : ...
187183 @overload
188184 def __rsub__ (self , other : datetime | Timestamp | np .datetime64 ) -> Timestamp : ... # type: ignore[misc]
189185 @overload
@@ -203,27 +199,27 @@ class Timedelta(timedelta):
203199 self , other : np_ndarray [ShapeT , np .timedelta64 ]
204200 ) -> np_ndarray [ShapeT , np .timedelta64 ]: ...
205201 @overload
206- def __rsub__ (self , other : pd . TimedeltaIndex ) -> pd . TimedeltaIndex : ...
202+ def __rsub__ (self , other : TimedeltaIndex ) -> TimedeltaIndex : ...
207203 def __neg__ (self ) -> Self : ...
208204 def __pos__ (self ) -> Self : ...
209205 def __abs__ (self ) -> Self : ...
210206 # Override due to more types supported than timedelta
211207 @overload # type: ignore[override]
212- def __mul__ (self , other : float ) -> Self : ...
208+ def __mul__ (self , other : Just [ float ] | Just [ int ] ) -> Self : ...
213209 @overload
214210 def __mul__ (
215211 self , other : np_ndarray [ShapeT , np .bool_ | np .integer | np .floating ]
216212 ) -> np_ndarray [ShapeT , np .timedelta64 ]: ...
217213 @overload
218- def __rmul__ (self , other : float ) -> Self : ...
214+ def __rmul__ (self , other : Just [ float ] | Just [ int ] ) -> Self : ...
219215 @overload
220216 def __rmul__ (
221217 self , other : np_ndarray [ShapeT , np .bool_ | np .integer | np .floating ]
222218 ) -> np_ndarray [ShapeT , np .timedelta64 ]: ...
223219 # Override due to more types supported than timedelta
224220 # error: Signature of "__floordiv__" incompatible with supertype "timedelta"
225221 @overload # type: ignore[override]
226- def __floordiv__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> int : ...
222+ def __floordiv__ (self , other : timedelta | np .timedelta64 | Self ) -> int : ...
227223 @overload
228224 def __floordiv__ (self , other : float ) -> Self : ...
229225 @overload
@@ -254,27 +250,29 @@ class Timedelta(timedelta):
254250 ) -> np_ndarray [ShapeT , np .int_ ]: ...
255251 # Override due to more types supported than timedelta
256252 @overload # type: ignore[override]
257- def __truediv__ (self , other : timedelta | Timedelta | NaTType ) -> float : ...
253+ # pyrefly: ignore[bad-override]
254+ def __truediv__ (self , other : Just [int ] | Just [float ]) -> Self : ...
258255 @overload
259- def __truediv__ (self , other : float ) -> Self : ...
256+ def __truediv__ (self , other : Self | NaTType ) -> float : ...
260257 @overload
261258 def __truediv__ (
262259 self , other : np_ndarray [ShapeT , np .integer | np .floating ]
263260 ) -> np_ndarray [ShapeT , np .timedelta64 ]: ...
264261 @overload
265- def __truediv__ (self , other : Series [ Timedelta ]) -> Series [ float ]: ...
266- @ overload
267- def __truediv__ ( self , other : Series [ int ] ) -> Series [ Timedelta ]: ...
262+ def __truediv__ (
263+ self , other : np_ndarray [ ShapeT , np . timedelta64 ]
264+ ) -> np_ndarray [ ShapeT , np . floating ]: ...
268265 @overload
269- def __truediv__ (self , other : Series [ float ] ) -> Series [ Timedelta ] : ...
266+ def __rtruediv__ (self , other : Self | NaTType ) -> float : ...
270267 @overload
271- def __truediv__ (self , other : Index [int ] | Index [float ]) -> TimedeltaIndex : ...
272- def __rtruediv__ (self , other : timedelta | Timedelta | NaTType ) -> float : ...
268+ def __rtruediv__ (
269+ self , other : np_ndarray [ShapeT , np .timedelta64 ]
270+ ) -> np_ndarray [ShapeT , np .floating ]: ...
273271 # Override due to more types supported than timedelta
274272 @overload
275- def __eq__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> bool : ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
273+ def __eq__ (self , other : timedelta | np .timedelta64 | Self ) -> bool : ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
276274 @overload
277- def __eq__ (self , other : Series [pd . Timedelta ]) -> Series [bool ]: ... # type: ignore[overload-overlap]
275+ def __eq__ (self , other : Series [Timedelta ]) -> Series [bool ]: ... # type: ignore[overload-overlap]
278276 @overload
279277 def __eq__ (self , other : Index ) -> np_1darray [np .bool ]: ... # type: ignore[overload-overlap]
280278 @overload
@@ -285,9 +283,9 @@ class Timedelta(timedelta):
285283 def __eq__ (self , other : object ) -> Literal [False ]: ...
286284 # Override due to more types supported than timedelta
287285 @overload
288- def __ne__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> bool : ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
286+ def __ne__ (self , other : timedelta | np .timedelta64 | Self ) -> bool : ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
289287 @overload
290- def __ne__ (self , other : Series [pd . Timedelta ]) -> Series [bool ]: ... # type: ignore[overload-overlap]
288+ def __ne__ (self , other : Series [Timedelta ]) -> Series [bool ]: ... # type: ignore[overload-overlap]
291289 @overload
292290 def __ne__ (self , other : Index ) -> np_1darray [np .bool ]: ... # type: ignore[overload-overlap]
293291 @overload
@@ -314,52 +312,50 @@ class Timedelta(timedelta):
314312 self , other : Series [int ] | Series [float ] | Series [Timedelta ]
315313 ) -> Series [Timedelta ]: ...
316314 def __divmod__ (self , other : timedelta ) -> tuple [int , Timedelta ]: ...
317- # Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
318- # for le, lt ge and gt
319315 # Override due to more types supported than timedelta
320316 @overload # type: ignore[override]
321- def __le__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> bool : ... # type: ignore[misc]
317+ def __le__ (self , other : timedelta | np .timedelta64 | Self ) -> bool : ...
322318 @overload
323319 def __le__ (self , other : TimedeltaIndex ) -> np_1darray [np .bool ]: ...
324320 @overload
325321 def __le__ (
326322 self , other : np_ndarray [ShapeT , np .timedelta64 ]
327323 ) -> np_ndarray [ShapeT , np .bool_ ]: ...
328324 @overload
329- def __le__ (self , other : Series [pd . Timedelta ]) -> Series [bool ]: ...
325+ def __le__ (self , other : Series [Timedelta ]) -> Series [bool ]: ...
330326 # Override due to more types supported than timedelta
331327 @overload # type: ignore[override]
332- def __lt__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> bool : ... # type: ignore[misc]
328+ def __lt__ (self , other : timedelta | np .timedelta64 | Self ) -> bool : ...
333329 @overload
334330 def __lt__ (self , other : TimedeltaIndex ) -> np_1darray [np .bool ]: ...
335331 @overload
336332 def __lt__ (
337333 self , other : np_ndarray [ShapeT , np .timedelta64 ]
338334 ) -> np_ndarray [ShapeT , np .bool_ ]: ...
339335 @overload
340- def __lt__ (self , other : Series [pd . Timedelta ]) -> Series [bool ]: ...
336+ def __lt__ (self , other : Series [Timedelta ]) -> Series [bool ]: ...
341337 # Override due to more types supported than timedelta
342338 @overload # type: ignore[override]
343- def __ge__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> bool : ... # type: ignore[misc]
339+ def __ge__ (self , other : timedelta | np .timedelta64 | Self ) -> bool : ...
344340 @overload
345341 def __ge__ (self , other : TimedeltaIndex ) -> np_1darray [np .bool ]: ...
346342 @overload
347343 def __ge__ (
348344 self , other : np_ndarray [ShapeT , np .timedelta64 ]
349345 ) -> np_ndarray [ShapeT , np .bool_ ]: ...
350346 @overload
351- def __ge__ (self , other : Series [pd . Timedelta ]) -> Series [bool ]: ...
347+ def __ge__ (self , other : Series [Timedelta ]) -> Series [bool ]: ...
352348 # Override due to more types supported than timedelta
353349 @overload # type: ignore[override]
354- def __gt__ (self , other : timedelta | Timedelta | np .timedelta64 ) -> bool : ... # type: ignore[misc]
350+ def __gt__ (self , other : timedelta | np .timedelta64 | Self ) -> bool : ...
355351 @overload
356352 def __gt__ (self , other : TimedeltaIndex ) -> np_1darray [np .bool ]: ...
357353 @overload
358354 def __gt__ (
359355 self , other : np_ndarray [ShapeT , np .timedelta64 ]
360356 ) -> np_ndarray [ShapeT , np .bool_ ]: ...
361357 @overload
362- def __gt__ (self , other : Series [pd . Timedelta ]) -> Series [bool ]: ...
358+ def __gt__ (self , other : Series [Timedelta ]) -> Series [bool ]: ...
363359 def __hash__ (self ) -> int : ...
364360 def isoformat (self ) -> str : ...
365361 def to_numpy (self ) -> np .timedelta64 : ...
0 commit comments