timestamps.pyi 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. from datetime import (
  2. date as _date,
  3. datetime,
  4. time as _time,
  5. timedelta,
  6. tzinfo as _tzinfo,
  7. )
  8. from time import struct_time
  9. from typing import (
  10. ClassVar,
  11. Literal,
  12. TypeAlias,
  13. overload,
  14. )
  15. import numpy as np
  16. from pandas._libs.tslibs import (
  17. BaseOffset,
  18. NaTType,
  19. Period,
  20. Tick,
  21. Timedelta,
  22. )
  23. from pandas._typing import (
  24. Self,
  25. TimestampNonexistent,
  26. )
  27. _TimeZones: TypeAlias = str | _tzinfo | None | int
  28. def integer_op_not_supported(obj: object) -> TypeError: ...
  29. class Timestamp(datetime):
  30. _creso: int
  31. min: ClassVar[Timestamp]
  32. max: ClassVar[Timestamp]
  33. resolution: ClassVar[Timedelta]
  34. _value: int # np.int64
  35. # error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
  36. def __new__( # type: ignore[misc]
  37. cls: type[Self],
  38. ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ...,
  39. year: int | None = ...,
  40. month: int | None = ...,
  41. day: int | None = ...,
  42. hour: int | None = ...,
  43. minute: int | None = ...,
  44. second: int | None = ...,
  45. microsecond: int | None = ...,
  46. tzinfo: _tzinfo | None = ...,
  47. *,
  48. nanosecond: int | None = ...,
  49. tz: _TimeZones = ...,
  50. unit: str | int | None = ...,
  51. fold: int | None = ...,
  52. ) -> Self | NaTType: ...
  53. @classmethod
  54. def _from_value_and_reso(
  55. cls, value: int, reso: int, tz: _TimeZones
  56. ) -> Timestamp: ...
  57. @property
  58. def value(self) -> int: ... # np.int64
  59. @property
  60. def year(self) -> int: ...
  61. @property
  62. def month(self) -> int: ...
  63. @property
  64. def day(self) -> int: ...
  65. @property
  66. def hour(self) -> int: ...
  67. @property
  68. def minute(self) -> int: ...
  69. @property
  70. def second(self) -> int: ...
  71. @property
  72. def microsecond(self) -> int: ...
  73. @property
  74. def nanosecond(self) -> int: ...
  75. @property
  76. def tzinfo(self) -> _tzinfo | None: ...
  77. @property
  78. def tz(self) -> _tzinfo | None: ...
  79. @property
  80. def fold(self) -> int: ...
  81. @classmethod
  82. def fromtimestamp(cls, ts: float, tz: _TimeZones = ...) -> Self: ...
  83. @classmethod
  84. def utcfromtimestamp(cls, ts: float) -> Self: ...
  85. @classmethod
  86. def today(cls, tz: _TimeZones = ...) -> Self: ...
  87. @classmethod
  88. def fromordinal(
  89. cls,
  90. ordinal: int,
  91. tz: _TimeZones = ...,
  92. ) -> Self: ...
  93. @classmethod
  94. def now(cls, tz: _TimeZones = ...) -> Self: ...
  95. @classmethod
  96. def utcnow(cls) -> Self: ...
  97. # error: Signature of "combine" incompatible with supertype "datetime"
  98. @classmethod
  99. def combine( # type: ignore[override]
  100. cls, date: _date, time: _time
  101. ) -> datetime: ...
  102. @classmethod
  103. def fromisoformat(cls, date_string: str) -> Self: ...
  104. def strftime(self, format: str) -> str: ...
  105. def __format__(self, fmt: str) -> str: ...
  106. def toordinal(self) -> int: ...
  107. def timetuple(self) -> struct_time: ...
  108. def timestamp(self) -> float: ...
  109. def utctimetuple(self) -> struct_time: ...
  110. def date(self) -> _date: ...
  111. def time(self) -> _time: ...
  112. def timetz(self) -> _time: ...
  113. # LSP violation: nanosecond is not present in datetime.datetime.replace
  114. # and has positional args following it
  115. def replace( # type: ignore[override]
  116. self,
  117. year: int | None = ...,
  118. month: int | None = ...,
  119. day: int | None = ...,
  120. hour: int | None = ...,
  121. minute: int | None = ...,
  122. second: int | None = ...,
  123. microsecond: int | None = ...,
  124. nanosecond: int | None = ...,
  125. tzinfo: _tzinfo | type[object] | None = ...,
  126. fold: int | None = ...,
  127. ) -> Self: ...
  128. # LSP violation: datetime.datetime.astimezone has a default value for tz
  129. def astimezone(self, tz: _TimeZones) -> Self: ... # type: ignore[override]
  130. def ctime(self) -> str: ...
  131. def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
  132. @classmethod
  133. def strptime(
  134. # Note: strptime is actually disabled and raises NotImplementedError
  135. cls,
  136. date_string: str,
  137. format: str,
  138. ) -> Self: ...
  139. def utcoffset(self) -> timedelta | None: ...
  140. def tzname(self) -> str | None: ...
  141. def dst(self) -> timedelta | None: ...
  142. def __le__(self, other: datetime) -> bool: ... # type: ignore[override]
  143. def __lt__(self, other: datetime) -> bool: ... # type: ignore[override]
  144. def __ge__(self, other: datetime) -> bool: ... # type: ignore[override]
  145. def __gt__(self, other: datetime) -> bool: ... # type: ignore[override]
  146. # error: Signature of "__add__" incompatible with supertype "date"/"datetime"
  147. @overload # type: ignore[override]
  148. def __add__(self, other: np.ndarray) -> np.ndarray: ...
  149. @overload
  150. def __add__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
  151. def __radd__(self, other: timedelta) -> Self: ...
  152. @overload # type: ignore[override]
  153. def __sub__(self, other: datetime) -> Timedelta: ...
  154. @overload
  155. def __sub__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
  156. def __hash__(self) -> int: ...
  157. def weekday(self) -> int: ...
  158. def isoweekday(self) -> int: ...
  159. # Return type "Tuple[int, int, int]" of "isocalendar" incompatible with return
  160. # type "_IsoCalendarDate" in supertype "date"
  161. def isocalendar(self) -> tuple[int, int, int]: ... # type: ignore[override]
  162. @property
  163. def is_leap_year(self) -> bool: ...
  164. @property
  165. def is_month_start(self) -> bool: ...
  166. @property
  167. def is_quarter_start(self) -> bool: ...
  168. @property
  169. def is_year_start(self) -> bool: ...
  170. @property
  171. def is_month_end(self) -> bool: ...
  172. @property
  173. def is_quarter_end(self) -> bool: ...
  174. @property
  175. def is_year_end(self) -> bool: ...
  176. def to_pydatetime(self, warn: bool = ...) -> datetime: ...
  177. def to_datetime64(self) -> np.datetime64: ...
  178. def to_period(self, freq: BaseOffset | str | None = None) -> Period: ...
  179. def to_julian_date(self) -> np.float64: ...
  180. @property
  181. def asm8(self) -> np.datetime64: ...
  182. def tz_convert(self, tz: _TimeZones) -> Self: ...
  183. # TODO: could return NaT?
  184. def tz_localize(
  185. self,
  186. tz: _TimeZones,
  187. ambiguous: bool | Literal["raise", "NaT"] = ...,
  188. nonexistent: TimestampNonexistent = ...,
  189. ) -> Self: ...
  190. def normalize(self) -> Self: ...
  191. # TODO: round/floor/ceil could return NaT?
  192. def round(
  193. self,
  194. freq: str,
  195. ambiguous: bool | Literal["raise", "NaT"] = ...,
  196. nonexistent: TimestampNonexistent = ...,
  197. ) -> Self: ...
  198. def floor(
  199. self,
  200. freq: str,
  201. ambiguous: bool | Literal["raise", "NaT"] = ...,
  202. nonexistent: TimestampNonexistent = ...,
  203. ) -> Self: ...
  204. def ceil(
  205. self,
  206. freq: str,
  207. ambiguous: bool | Literal["raise", "NaT"] = ...,
  208. nonexistent: TimestampNonexistent = ...,
  209. ) -> Self: ...
  210. def day_name(self, locale: str | None = ...) -> str: ...
  211. def month_name(self, locale: str | None = ...) -> str: ...
  212. @property
  213. def day_of_week(self) -> int: ...
  214. @property
  215. def dayofweek(self) -> int: ...
  216. @property
  217. def day_of_year(self) -> int: ...
  218. @property
  219. def dayofyear(self) -> int: ...
  220. @property
  221. def quarter(self) -> int: ...
  222. @property
  223. def week(self) -> int: ...
  224. def to_numpy(
  225. self, dtype: np.dtype | None = ..., copy: bool = ...
  226. ) -> np.datetime64: ...
  227. @property
  228. def _date_repr(self) -> str: ...
  229. @property
  230. def days_in_month(self) -> int: ...
  231. @property
  232. def daysinmonth(self) -> int: ...
  233. @property
  234. def unit(self) -> str: ...
  235. def as_unit(self, unit: str, round_ok: bool = ...) -> Timestamp: ...