offsets.pyi 8.1 KB

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