offsets.pyi 8.1 KB

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