@@ -13,6 +13,7 @@ from pandas import (
13
13
Index ,
14
14
PeriodIndex ,
15
15
Timedelta ,
16
+ TimedeltaIndex ,
16
17
)
17
18
from pandas .core .accessor import PandasDelegate
18
19
from pandas .core .arrays import (
@@ -156,6 +157,7 @@ _DTRoundingMethodReturnType = TypeVar(
156
157
TimedeltaSeries ,
157
158
TimestampSeries ,
158
159
DatetimeIndex ,
160
+ # TimedeltaIndex
159
161
)
160
162
161
163
class _DatetimeRoundingMethods (Generic [_DTRoundingMethodReturnType ]):
@@ -278,23 +280,30 @@ class DatetimeProperties(
278
280
def to_pydatetime (self ) -> np .ndarray : ...
279
281
def isocalendar (self ) -> DataFrame : ...
280
282
281
- class _TimedeltaPropertiesNoRounding :
283
+ _TDNoRoundingMethodReturnType = TypeVar (
284
+ "_TDNoRoundingMethodReturnType" , Series [int ], Index
285
+ )
286
+ _TDTotalSecondsReturnType = TypeVar ("_TDTotalSecondsReturnType" , Series [float ], Index )
287
+
288
+ class _TimedeltaPropertiesNoRounding (
289
+ Generic [_TDNoRoundingMethodReturnType , _TDTotalSecondsReturnType ]
290
+ ):
282
291
def to_pytimedelta (self ) -> np .ndarray : ...
283
292
@property
284
293
def components (self ) -> DataFrame : ...
285
294
@property
286
- def days (self ) -> Series [ int ] : ...
295
+ def days (self ) -> _TDNoRoundingMethodReturnType : ...
287
296
@property
288
- def seconds (self ) -> Series [ int ] : ...
297
+ def seconds (self ) -> _TDNoRoundingMethodReturnType : ...
289
298
@property
290
- def microseconds (self ) -> Series [ int ] : ...
299
+ def microseconds (self ) -> _TDNoRoundingMethodReturnType : ...
291
300
@property
292
- def nanoseconds (self ) -> Series [ int ] : ...
293
- def total_seconds (self ) -> Series [ float ] : ...
301
+ def nanoseconds (self ) -> _TDNoRoundingMethodReturnType : ...
302
+ def total_seconds (self ) -> _TDTotalSecondsReturnType : ...
294
303
295
304
class TimedeltaProperties (
296
305
Properties ,
297
- _TimedeltaPropertiesNoRounding ,
306
+ _TimedeltaPropertiesNoRounding [ Series [ int ], Series [ float ]] ,
298
307
_DatetimeRoundingMethods [TimedeltaSeries ],
299
308
): ...
300
309
@@ -337,7 +346,7 @@ class CombinedDatetimelikeProperties(
337
346
Series [str ],
338
347
PeriodSeries ,
339
348
],
340
- _TimedeltaPropertiesNoRounding ,
349
+ _TimedeltaPropertiesNoRounding [ Series [ int ], Series [ float ]] ,
341
350
_PeriodProperties ,
342
351
):
343
352
def __new__ (cls , data : Series ): ...
@@ -379,3 +388,32 @@ class DatetimeIndexProperties(
379
388
def std (
380
389
self , axis : int | None = ..., ddof : int = ..., skipna : bool = ...
381
390
) -> Timedelta : ...
391
+
392
+ # For some reason, using TimedeltaIndex as an argument to _DatetimeRoundingMethods
393
+ # doesn't work for pyright. So we just make the rounding methods explicit here.
394
+ class TimedeltaIndexProperties (
395
+ Properties ,
396
+ _TimedeltaPropertiesNoRounding [Index , Index ],
397
+ # _DatetimeRoundingMethods[TimedeltaIndex],
398
+ ):
399
+ def round (
400
+ self ,
401
+ freq : str | BaseOffset | None ,
402
+ ambiguous : Literal ["raise" , "infer" , "NaT" ] | np_ndarray_bool = ...,
403
+ nonexistent : Literal ["shift_forward" , "shift_backward" , "NaT" , "raise" ]
404
+ | Timedelta = ...,
405
+ ) -> TimedeltaIndex : ...
406
+ def floor (
407
+ self ,
408
+ freq : str | BaseOffset | None ,
409
+ ambiguous : Literal ["raise" , "infer" , "NaT" ] | np_ndarray_bool = ...,
410
+ nonexistent : Literal ["shift_forward" , "shift_backward" , "NaT" , "raise" ]
411
+ | Timedelta = ...,
412
+ ) -> TimedeltaIndex : ...
413
+ def ceil (
414
+ self ,
415
+ freq : str | BaseOffset | None ,
416
+ ambiguous : Literal ["raise" , "infer" , "NaT" ] | np_ndarray_bool = ...,
417
+ nonexistent : Literal ["shift_forward" , "shift_backward" , "NaT" , "raise" ]
418
+ | Timedelta = ...,
419
+ ) -> TimedeltaIndex : ...
0 commit comments