1
1
from __future__ import annotations
2
- from datetime import datetime
3
- from typing import Any , Tuple , Union
4
- from datetime import timedelta
2
+
3
+ from datetime import (
4
+ datetime ,
5
+ timedelta ,
6
+ )
7
+ from typing import (
8
+ TYPE_CHECKING ,
9
+ Any ,
10
+ Collection ,
11
+ Literal ,
12
+ Tuple ,
13
+ TypeVar ,
14
+ Union ,
15
+ overload ,
16
+ )
17
+
18
+ import numpy as np
19
+
20
+ from pandas ._typing import npt
21
+
22
+ from .timedeltas import Timedelta
23
+
24
+ if TYPE_CHECKING :
25
+ from pandas .core .indexes .datetimes import DatetimeIndex
26
+ _BaseOffsetT = TypeVar ("_BaseOffsetT" , bound = "BaseOffset" )
27
+ _DatetimeT = TypeVar ("_DatetimeT" , bound = datetime )
28
+ _TimedeltaT = TypeVar ("_TimedeltaT" , bound = timedelta )
29
+
30
+ _relativedelta_kwds : set [str ]
31
+ prefix_mapping : dict [str , type ]
32
+
33
+ class ApplyTypeError (TypeError ): ...
5
34
6
35
class BaseOffset :
36
+ n : int
7
37
def __init__ (self , n : int = ..., normalize : bool = ...) -> None : ...
8
38
def __eq__ (self , other ) -> bool : ...
9
39
def __ne__ (self , other ) -> bool : ...
@@ -12,21 +42,49 @@ class BaseOffset:
12
42
def kwds (self ) -> dict : ...
13
43
@property
14
44
def base (self ) -> BaseOffset : ...
15
- def __add__ (self , other ) -> BaseOffset : ...
16
- def __sub__ (self , other ) -> BaseOffset : ...
45
+ @overload
46
+ def __add__ (self , other : npt .NDArray [np .object_ ]) -> npt .NDArray [np .object_ ]: ...
47
+ @overload
48
+ def __add__ (self : _BaseOffsetT , other : BaseOffset ) -> _BaseOffsetT : ...
49
+ @overload
50
+ def __add__ (self , other : _DatetimeT ) -> _DatetimeT : ...
51
+ @overload
52
+ def __add__ (self , other : _TimedeltaT ) -> _TimedeltaT : ...
53
+ @overload
54
+ def __radd__ (self , other : npt .NDArray [np .object_ ]) -> npt .NDArray [np .object_ ]: ...
55
+ @overload
56
+ def __radd__ (self : _BaseOffsetT , other : BaseOffset ) -> _BaseOffsetT : ...
57
+ @overload
58
+ def __radd__ (self , other : _DatetimeT ) -> _DatetimeT : ...
59
+ @overload
60
+ def __radd__ (self , other : _TimedeltaT ) -> _TimedeltaT : ...
61
+ def __sub__ (self : _BaseOffsetT , other : BaseOffset ) -> _BaseOffsetT : ...
62
+ @overload
63
+ def __rsub__ (self , other : npt .NDArray [np .object_ ]) -> npt .NDArray [np .object_ ]: ...
64
+ @overload
65
+ def __rsub__ (self : _BaseOffsetT , other : BaseOffset ) -> _BaseOffsetT : ...
66
+ @overload
67
+ def __rsub__ (self , other : _DatetimeT ) -> _DatetimeT : ...
68
+ @overload
69
+ def __rsub__ (self , other : _TimedeltaT ) -> _TimedeltaT : ...
17
70
def __call__ (self , other ): ...
18
- def __mul__ (self , other ): ...
19
- def __neg__ (self ) -> BaseOffset : ...
20
- def copy (self ) -> BaseOffset : ...
71
+ @overload
72
+ def __mul__ (self , other : np .ndarray ) -> np .ndarray : ...
73
+ @overload
74
+ def __mul__ (self : _BaseOffsetT , other : int ) -> _BaseOffsetT : ...
75
+ @overload
76
+ def __rmul__ (self , other : np .ndarray ) -> np .ndarray : ...
77
+ @overload
78
+ def __rmul__ (self : _BaseOffsetT , other : int ) -> _BaseOffsetT : ...
79
+ def __neg__ (self : _BaseOffsetT ) -> _BaseOffsetT : ...
80
+ def copy (self : _BaseOffsetT ) -> _BaseOffsetT : ...
21
81
def __repr__ (self ) -> str : ...
22
82
@property
23
83
def name (self ) -> str : ...
24
84
@property
25
85
def rule_code (self ) -> str : ...
26
86
def freqstr (self ) -> str : ...
27
- # Next one is problematic due to circular imports
28
- #def apply_index(self, dtindex: DatetimeIndex) -> DatetimeIndex: ...
29
- def apply_index (self , dtindex ): ...
87
+ def apply_index (self , dtindex : "DatetimeIndex" ) -> "DatetimeIndex" : ...
30
88
def _apply_array (self , dtarr ) -> None : ...
31
89
def rollback (self , dt : datetime ) -> datetime : ...
32
90
def rollforward (self , dt : datetime ) -> datetime : ...
@@ -39,15 +97,26 @@ class BaseOffset:
39
97
def isAnchored (self ) -> bool : ...
40
98
def is_anchored (self ) -> bool : ...
41
99
100
+ def _get_offset (name : str ) -> BaseOffset : ...
101
+
42
102
class SingleConstructorOffset (BaseOffset ):
43
103
@classmethod
44
- def _from_name (cls , suffix = None ): ...
104
+ def _from_name (cls , suffix = ... ): ...
45
105
def __reduce__ (self ): ...
46
106
47
- def to_offset (freq : Union [str , Tuple , timedelta , BaseOffset , None ]) -> Union [BaseOffset , None ]: ...
107
+ @overload
108
+ def to_offset (freq : None ) -> None : ...
109
+ @overload
110
+ def to_offset (freq : timedelta | BaseOffset | str ) -> BaseOffset : ...
48
111
49
112
class Tick (SingleConstructorOffset ):
50
113
def __init__ (self , n : int = ..., normalize : bool = ...) -> None : ...
114
+ @property
115
+ def delta (self ) -> Timedelta : ...
116
+ @property
117
+ def nanos (self ) -> int : ...
118
+
119
+ def delta_to_tick (delta : timedelta ) -> Tick : ...
51
120
52
121
class Day (Tick ): ...
53
122
class Hour (Tick ): ...
@@ -56,18 +125,44 @@ class Second(Tick): ...
56
125
class Milli (Tick ): ...
57
126
class Micro (Tick ): ...
58
127
class Nano (Tick ): ...
128
+
59
129
class RelativeDeltaOffset (BaseOffset ):
60
130
def __init__ (self , n : int = ..., normalize : bool = ..., ** kwds : Any ) -> None : ...
61
- class BusinessMixin (SingleConstructorOffset ): ...
131
+
132
+ class BusinessMixin (SingleConstructorOffset ):
133
+ def __init__ (
134
+ self , n : int = ..., normalize : bool = ..., offset : timedelta = ...
135
+ ): ...
136
+
62
137
class BusinessDay (BusinessMixin ): ...
63
- class BusinessHour (BusinessMixin ): ...
138
+
139
+ class BusinessHour (BusinessMixin ):
140
+ def __init__ (
141
+ self ,
142
+ n : int = ...,
143
+ normalize : bool = ...,
144
+ start : str | Collection [str ] = ...,
145
+ end : str | Collection [str ] = ...,
146
+ offset : timedelta = ...,
147
+ ): ...
148
+
64
149
class WeekOfMonthMixin (SingleConstructorOffset ): ...
65
- class YearOffset (SingleConstructorOffset ): ...
150
+
151
+ class YearOffset (SingleConstructorOffset ):
152
+ def __init__ (
153
+ self , n : int = ..., normalize : bool = ..., month : int | None = ...
154
+ ): ...
155
+
66
156
class BYearEnd (YearOffset ): ...
67
157
class BYearBegin (YearOffset ): ...
68
158
class YearEnd (YearOffset ): ...
69
159
class YearBegin (YearOffset ): ...
70
- class QuarterOffset (SingleConstructorOffset ): ...
160
+
161
+ class QuarterOffset (SingleConstructorOffset ):
162
+ def __init__ (
163
+ self , n : int = ..., normalize : bool = ..., startingMonth : int | None = ...
164
+ ) -> None : ...
165
+
71
166
class BQuarterEnd (QuarterOffset ): ...
72
167
class BQuarterBegin (QuarterOffset ): ...
73
168
class QuarterEnd (QuarterOffset ): ...
@@ -77,19 +172,66 @@ class MonthEnd(MonthOffset): ...
77
172
class MonthBegin (MonthOffset ): ...
78
173
class BusinessMonthEnd (MonthOffset ): ...
79
174
class BusinessMonthBegin (MonthOffset ): ...
80
- class SemiMonthOffset (SingleConstructorOffset ): ...
175
+
176
+ class SemiMonthOffset (SingleConstructorOffset ):
177
+ def __init__ (
178
+ self , n : int = ..., normalize : bool = ..., day_of_month : int | None = ...
179
+ ) -> None : ...
180
+
81
181
class SemiMonthEnd (SemiMonthOffset ): ...
82
182
class SemiMonthBegin (SemiMonthOffset ): ...
83
- class Week (SingleConstructorOffset ): ...
183
+
184
+ class Week (SingleConstructorOffset ):
185
+ def __init__ (
186
+ self , n : int = ..., normalize : bool = ..., weekday : int | None = ...
187
+ ) -> None : ...
188
+
84
189
class WeekOfMonth (WeekOfMonthMixin ): ...
85
190
class LastWeekOfMonth (WeekOfMonthMixin ): ...
86
- class FY5253Mixin (SingleConstructorOffset ): ...
191
+
192
+ class FY5253Mixin (SingleConstructorOffset ):
193
+ def __init__ (
194
+ self ,
195
+ n : int = ...,
196
+ normalize : bool = ...,
197
+ weekday : int = ...,
198
+ startingMonth : int = ...,
199
+ variation : str = ...,
200
+ ) -> None : ...
201
+
87
202
class FY5253 (FY5253Mixin ): ...
88
203
class FY5253Quarter (FY5253Mixin ): ...
89
204
class Easter (SingleConstructorOffset ): ...
90
- class _CustomBusinessMonth (BusinessMixin ): ...
91
- class CustomBusinessDay (BusinessDay ): ...
92
- class CustomBusinessHour (BusinessHour ): ...
205
+
206
+ class _CustomBusinessMonth (BusinessMixin ):
207
+ def __init__ (
208
+ self ,
209
+ n : int = ...,
210
+ normalize : bool = ...,
211
+ offset : timedelta = ...,
212
+ holidays : None | list = ...,
213
+ ): ...
214
+
215
+ class CustomBusinessDay (BusinessDay ):
216
+ def __init__ (
217
+ self ,
218
+ n : int = ...,
219
+ normalize : bool = ...,
220
+ offset : timedelta = ...,
221
+ weekmask : str = ...,
222
+ ): ...
223
+
224
+ class CustomBusinessHour (BusinessHour ):
225
+ def __init__ (
226
+ self ,
227
+ n : int = ...,
228
+ normalize : bool = ...,
229
+ start : str = ...,
230
+ end : str = ...,
231
+ offset : timedelta = ...,
232
+ holidays : None | list = ...,
233
+ ): ...
234
+
93
235
class CustomBusinessMonthEnd (_CustomBusinessMonth ): ...
94
236
class CustomBusinessMonthBegin (_CustomBusinessMonth ): ...
95
237
class DateOffset (RelativeDeltaOffset ): ...
@@ -100,3 +242,15 @@ BMonthBegin = BusinessMonthBegin
100
242
CBMonthEnd = CustomBusinessMonthEnd
101
243
CBMonthBegin = CustomBusinessMonthBegin
102
244
CDay = CustomBusinessDay
245
+
246
+ def roll_qtrday (
247
+ other : datetime , n : int , month : int , day_opt : str , modby : int
248
+ ) -> int : ...
249
+
250
+ INVALID_FREQ_ERR_MSG : Literal ["Invalid frequency: {0}" ]
251
+
252
+ def shift_months (
253
+ dtindex : npt .NDArray [np .int64 ], months : int , day_opt : str | None = ...
254
+ ) -> npt .NDArray [np .int64 ]: ...
255
+
256
+ _offset_map : dict [str , BaseOffset ]
0 commit comments