@@ -4,9 +4,11 @@ from datetime import (
4
4
tzinfo as _tzinfo ,
5
5
)
6
6
from typing import (
7
+ Any ,
7
8
Generic ,
8
9
Literal ,
9
10
TypeVar ,
11
+ overload ,
10
12
)
11
13
12
14
import numpy as np
@@ -17,6 +19,7 @@ from pandas import (
17
19
PeriodIndex ,
18
20
Timedelta ,
19
21
TimedeltaIndex ,
22
+ Timestamp ,
20
23
)
21
24
from pandas .core .accessor import PandasDelegate
22
25
from pandas .core .arrays import (
@@ -29,12 +32,12 @@ from pandas.core.series import (
29
32
PeriodSeries ,
30
33
Series ,
31
34
TimedeltaSeries ,
32
- TimestampSeries ,
33
35
)
34
36
35
37
from pandas ._libs .tslibs import BaseOffset
36
38
from pandas ._libs .tslibs .offsets import DateOffset
37
39
from pandas ._typing import (
40
+ S1 ,
38
41
TimeAmbiguous ,
39
42
TimeNonexistent ,
40
43
TimestampConvention ,
@@ -155,14 +158,13 @@ class _DatetimeLikeOps(
155
158
],
156
159
): ...
157
160
158
- # Ideally, the rounding methods would return TimestampSeries when `Series.dt.method`
161
+ # Ideally, the rounding methods would return Series[Timestamp] when `Series.dt.method`
159
162
# is invoked, but because of how Series.dt is hooked in and that we may not know the
160
163
# type of the series, we don't know which kind of series was ...ed
161
164
# in to the dt accessor
162
165
163
166
_DTTimestampTimedeltaReturnType = TypeVar (
164
- "_DTTimestampTimedeltaReturnType" ,
165
- bound = Series | TimestampSeries | TimedeltaSeries | DatetimeIndex | TimedeltaIndex ,
167
+ "_DTTimestampTimedeltaReturnType" , bound = Series | DatetimeIndex | TimedeltaIndex
166
168
)
167
169
168
170
class _DatetimeRoundingMethods (Generic [_DTTimestampTimedeltaReturnType ]):
@@ -198,7 +200,7 @@ class _DatetimeRoundingMethods(Generic[_DTTimestampTimedeltaReturnType]):
198
200
) -> _DTTimestampTimedeltaReturnType : ...
199
201
200
202
_DTNormalizeReturnType = TypeVar (
201
- "_DTNormalizeReturnType" , TimestampSeries , DatetimeIndex
203
+ "_DTNormalizeReturnType" , Series [ Timestamp ] , DatetimeIndex
202
204
)
203
205
_DTStrKindReturnType = TypeVar ("_DTStrKindReturnType" , bound = Series [str ] | Index )
204
206
_DTToPeriodReturnType = TypeVar (
@@ -320,7 +322,7 @@ class TimedeltaProperties(
320
322
def as_unit (self , unit : TimeUnit ) -> TimedeltaSeries : ...
321
323
322
324
_PeriodDTReturnTypes = TypeVar (
323
- "_PeriodDTReturnTypes" , bound = TimestampSeries | DatetimeIndex
325
+ "_PeriodDTReturnTypes" , bound = Series [ Timestamp ] | DatetimeIndex
324
326
)
325
327
_PeriodIntReturnTypes = TypeVar ("_PeriodIntReturnTypes" , bound = Series [int ] | Index [int ])
326
328
_PeriodStrReturnTypes = TypeVar ("_PeriodStrReturnTypes" , bound = Series [str ] | Index )
@@ -363,7 +365,7 @@ class PeriodIndexFieldOps(
363
365
class PeriodProperties (
364
366
Properties ,
365
367
_PeriodProperties [
366
- TimestampSeries , Series [int ], Series [str ], DatetimeArray , PeriodArray
368
+ Series [ Timestamp ] , Series [int ], Series [str ], DatetimeArray , PeriodArray
367
369
],
368
370
_DatetimeFieldOps [Series [int ]],
369
371
_IsLeapYearProperty ,
@@ -377,7 +379,7 @@ class CombinedDatetimelikeProperties(
377
379
Series [dt .date ],
378
380
Series [dt .time ],
379
381
str ,
380
- TimestampSeries ,
382
+ Series [ Timestamp ] ,
381
383
Series [str ],
382
384
PeriodSeries ,
383
385
],
@@ -388,11 +390,11 @@ class TimestampProperties(
388
390
DatetimeProperties [
389
391
Series [int ],
390
392
Series [bool ],
391
- TimestampSeries ,
393
+ Series [ Timestamp ] ,
392
394
Series [dt .date ],
393
395
Series [dt .time ],
394
396
str ,
395
- TimestampSeries ,
397
+ Series [ Timestamp ] ,
396
398
Series [str ],
397
399
PeriodSeries ,
398
400
]
@@ -427,3 +429,44 @@ class TimedeltaIndexProperties(
427
429
_TimedeltaPropertiesNoRounding [Index , Index ],
428
430
_DatetimeRoundingMethods [TimedeltaIndex ],
429
431
): ...
432
+
433
+ class _dtDescriptor (CombinedDatetimelikeProperties , Generic [S1 ]):
434
+ @overload
435
+ def __get__ (
436
+ self , instance : Series [Timestamp ], owner : Any
437
+ ) -> TimestampProperties : ...
438
+ @overload
439
+ def __get__ (
440
+ self , instance : Series [S1 ], owner : Any
441
+ ) -> CombinedDatetimelikeProperties : ...
442
+ def round (
443
+ self ,
444
+ freq : str | BaseOffset | None ,
445
+ ambiguous : Literal ["raise" , "infer" , "NaT" ] | bool | np_ndarray_bool = ...,
446
+ nonexistent : (
447
+ Literal ["shift_forward" , "shift_backward" , "NaT" , "raise" ]
448
+ | timedelta
449
+ | Timedelta
450
+ ) = ...,
451
+ ) -> Series [S1 ]: ...
452
+ def floor (
453
+ self ,
454
+ freq : str | BaseOffset | None ,
455
+ ambiguous : Literal ["raise" , "infer" , "NaT" ] | bool | np_ndarray_bool = ...,
456
+ nonexistent : (
457
+ Literal ["shift_forward" , "shift_backward" , "NaT" , "raise" ]
458
+ | timedelta
459
+ | Timedelta
460
+ ) = ...,
461
+ ) -> Series [S1 ]: ...
462
+ def ceil (
463
+ self ,
464
+ freq : str | BaseOffset | None ,
465
+ ambiguous : Literal ["raise" , "infer" , "NaT" ] | bool | np_ndarray_bool = ...,
466
+ nonexistent : (
467
+ Literal ["shift_forward" , "shift_backward" , "NaT" , "raise" ]
468
+ | timedelta
469
+ | Timedelta
470
+ ) = ...,
471
+ ) -> Series [S1 ]: ...
472
+ def as_unit (self , unit : TimeUnit ) -> Series [S1 ]: ...
0 commit comments