This commit is contained in:
2025-09-07 22:09:54 +02:00
parent e1b817252c
commit 2fc0d000b6
7796 changed files with 2159515 additions and 933 deletions

View File

@ -0,0 +1,10 @@
from pandas._libs.interval import Interval as Interval
from pandas._libs.tslibs import (
NaT as NaT,
NaTType as NaTType,
OutOfBoundsDatetime as OutOfBoundsDatetime,
Period as Period,
Timedelta as Timedelta,
Timestamp as Timestamp,
iNaT as iNaT,
)

View File

@ -0,0 +1,4 @@
class _NDFrameIndexerBase:
def __init__(self, name: str, obj: object) -> None: ...
@property
def ndim(self) -> int: ...

View File

@ -0,0 +1,247 @@
from typing import (
Any,
Generic,
Literal,
TypeVar,
overload,
)
import numpy as np
from pandas import (
IntervalIndex,
Series,
Timedelta,
Timestamp,
)
from pandas.core.series import (
TimedeltaSeries,
TimestampSeries,
)
from pandas._typing import (
IntervalClosedType,
IntervalT,
np_1darray,
npt,
)
VALID_CLOSED: frozenset[str]
_OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float)
_OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta)
_OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta)
class _LengthDescriptor:
@overload
def __get__(
self, instance: Interval[_OrderableScalarT], owner: Any
) -> _OrderableScalarT: ...
@overload
def __get__(
self, instance: Interval[_OrderableTimesT], owner: Any
) -> Timedelta: ...
@overload
def __get__(self, instance: IntervalTree, owner: Any) -> np.ndarray: ...
class _MidDescriptor:
@overload
def __get__(self, instance: Interval[_OrderableScalarT], owner: Any) -> float: ...
@overload
def __get__(
self, instance: Interval[_OrderableTimesT], owner: Any
) -> _OrderableTimesT: ...
@overload
def __get__(self, instance: IntervalTree, owner: Any) -> np.ndarray: ...
class IntervalMixin:
@property
def closed_left(self) -> bool: ...
@property
def closed_right(self) -> bool: ...
@property
def open_left(self) -> bool: ...
@property
def open_right(self) -> bool: ...
@property
def is_empty(self) -> bool: ...
class Interval(IntervalMixin, Generic[_OrderableT]):
@property
def left(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def closed(self) -> IntervalClosedType: ...
mid: _MidDescriptor
length: _LengthDescriptor
def __init__(
self,
left: _OrderableT,
right: _OrderableT,
closed: IntervalClosedType = ...,
) -> None: ...
def __hash__(self) -> int: ...
# for __contains__, it seems that we have to separate out the 4 cases to make
# mypy happy
@overload
def __contains__(self: Interval[Timestamp], key: Timestamp) -> bool: ...
@overload
def __contains__(self: Interval[Timedelta], key: Timedelta) -> bool: ...
@overload
def __contains__(self: Interval[int], key: float) -> bool: ...
@overload
def __contains__(self: Interval[float], key: float) -> bool: ...
@overload
def __add__(self: Interval[Timestamp], y: Timedelta) -> Interval[Timestamp]: ...
@overload
def __add__(self: Interval[Timedelta], y: Timedelta) -> Interval[Timedelta]: ...
@overload
def __add__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __add__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __radd__(
self: Interval[_OrderableTimesT], y: Timedelta
) -> Interval[_OrderableTimesT]: ...
@overload
def __radd__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __radd__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __sub__(
self: Interval[_OrderableTimesT], y: Timedelta
) -> Interval[_OrderableTimesT]: ...
@overload
def __sub__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __sub__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __rsub__(
self: Interval[_OrderableTimesT], y: Timedelta
) -> Interval[_OrderableTimesT]: ...
@overload
def __rsub__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __rsub__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __mul__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __mul__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __mul__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
@overload
def __rmul__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __rmul__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __rmul__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
@overload
def __truediv__(self: Interval[int], y: float) -> Interval[float]: ...
@overload
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __truediv__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
@overload
def __floordiv__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __floordiv__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
@overload
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
@overload
def overlaps(self: Interval[int], other: Interval[float]) -> bool: ...
@overload
def overlaps(self: Interval[float], other: Interval[int]) -> bool: ...
@overload
def __gt__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __gt__(
self: IntervalT, other: IntervalIndex[IntervalT]
) -> np_1darray[np.bool]: ...
@overload
def __gt__(
self,
other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries,
) -> Series[bool]: ...
@overload
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __lt__(
self: IntervalT, other: IntervalIndex[IntervalT]
) -> np_1darray[np.bool]: ...
@overload
def __lt__(
self,
other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries,
) -> Series[bool]: ...
@overload
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __ge__(
self: IntervalT, other: IntervalIndex[IntervalT]
) -> np_1darray[np.bool]: ...
@overload
def __ge__(
self,
other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries,
) -> Series[bool]: ...
@overload
def __le__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __le__(
self: IntervalT, other: IntervalIndex[IntervalT]
) -> np_1darray[np.bool]: ...
@overload
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(
self: IntervalT, other: IntervalIndex[IntervalT]
) -> np_1darray[np.bool]: ...
@overload
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(
self: IntervalT, other: IntervalIndex[IntervalT]
) -> np_1darray[np.bool]: ...
@overload
def __ne__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: object) -> Literal[True]: ...
class IntervalTree(IntervalMixin):
def __init__(
self,
left: np.ndarray,
right: np.ndarray,
closed: IntervalClosedType = ...,
leaf_size: int = ...,
) -> None: ...
def get_indexer(self, target) -> npt.NDArray[np.intp]: ...
def get_indexer_non_unique(
self, target
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
_na_count: int
@property
def is_overlapping(self) -> bool: ...
@property
def is_monotonic_increasing(self) -> bool: ...
def clear_mapping(self) -> None: ...

View File

@ -0,0 +1,4 @@
def decode(*args, **kwargs): ...
def dumps(*args, **kwargs): ...
def encode(*args, **kwargs): ...
def loads(*args, **kwargs): ...

View File

@ -0,0 +1,26 @@
from enum import Enum
from typing import (
Final,
Literal,
)
import numpy as np
from typing_extensions import (
TypeAlias,
TypeGuard,
)
class _NoDefault(Enum):
no_default = ...
no_default: Final = _NoDefault.no_default
_NoDefaultDoNotUse: TypeAlias = Literal[_NoDefault.no_default] # noqa: PYI047
def infer_dtype(value: object, skipna: bool = True) -> str: ...
def is_iterator(obj: object) -> bool: ...
def is_scalar(val: object) -> bool: ...
def is_list_like(obj: object, allow_sets: bool = True) -> bool: ...
def is_complex(val: object) -> TypeGuard[complex]: ...
def is_bool(val: object) -> TypeGuard[bool | np.bool_]: ...
def is_integer(val: object) -> TypeGuard[int | np.integer]: ...
def is_float(val: object) -> TypeGuard[float | np.floating]: ...

View File

@ -0,0 +1,46 @@
from typing_extensions import Self
class NAType:
def __new__(cls, *args, **kwargs) -> Self: ...
def __format__(self, format_spec: str) -> str: ...
def __bool__(self) -> None: ...
def __hash__(self) -> int: ...
def __reduce__(self) -> str: ...
def __add__(self, other) -> NAType: ...
def __radd__(self, other) -> NAType: ...
def __sub__(self, other) -> NAType: ...
def __rsub__(self, other) -> NAType: ...
def __mul__(self, other) -> NAType: ...
def __rmul__(self, other) -> NAType: ...
def __matmul__(self, other) -> NAType: ...
def __rmatmul__(self, other) -> NAType: ...
def __truediv__(self, other) -> NAType: ...
def __rtruediv__(self, other) -> NAType: ...
def __floordiv__(self, other) -> NAType: ...
def __rfloordiv__(self, other) -> NAType: ...
def __mod__(self, other) -> NAType: ...
def __rmod__(self, other) -> NAType: ...
def __divmod__(self, other) -> NAType: ...
def __rdivmod__(self, other) -> NAType: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __ge__(self, other) -> bool: ...
def __neg__(self, other) -> NAType: ...
def __pos__(self, other) -> NAType: ...
def __abs__(self, other) -> NAType: ...
def __invert__(self, other) -> NAType: ...
def __pow__(self, other) -> NAType: ...
def __rpow__(self, other) -> NAType: ...
def __and__(self, other) -> NAType | None: ...
__rand__ = __and__
def __or__(self, other) -> bool | NAType: ...
__ror__ = __or__
def __xor__(self, other) -> NAType: ...
__rxor__ = __xor__
__array_priority__: int
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ...
NA: NAType = ...

View File

@ -0,0 +1,16 @@
from collections.abc import Callable
class CachedProperty:
def __init__(self, func: Callable) -> None: ...
def __get__(self, obj, typ): ...
def __set__(self, obj, value) -> None: ...
# note: this is a lie to make type checkers happy (they special
# case property). cache_readonly uses attribute names similar to
# property (fget) but it does not provide fset and fdel.
cache_readonly = property
class AxisProperty:
def __init__(self, axis: int = ..., doc: str = ...) -> None: ...
def __get__(self, obj, typ): ...
def __set__(self, obj, value) -> None: ...

View File

@ -0,0 +1,3 @@
class SparseIndex: ...
class BlockIndex(SparseIndex): ...
class IntIndex(SparseIndex): ...

View File

@ -0,0 +1,29 @@
__all__ = [
"Period",
"Timestamp",
"Timedelta",
"NaT",
"NaTType",
"iNaT",
"nat_strings",
"BaseOffset",
"Tick",
"OutOfBoundsDatetime",
]
from pandas._libs.tslibs.nattype import (
NaT,
NaTType,
iNaT,
nat_strings,
)
from pandas._libs.tslibs.np_datetime import (
OutOfBoundsDatetime as OutOfBoundsDatetime,
OutOfBoundsTimedelta as OutOfBoundsTimedelta,
)
from pandas._libs.tslibs.offsets import (
BaseOffset,
Tick,
)
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._libs.tslibs.timestamps import Timestamp

View File

@ -0,0 +1,3 @@
from datetime import datetime
class ABCTimestamp(datetime): ...

View File

@ -0,0 +1 @@
class OutOfBoundsTimedelta(ValueError): ...

View File

@ -0,0 +1,157 @@
# pyright: strict
from datetime import (
datetime,
timedelta,
tzinfo as _tzinfo,
)
from typing import Literal
import numpy as np
from typing_extensions import (
Self,
TypeAlias,
)
from pandas._libs.tslibs.period import Period
from pandas._typing import (
Frequency,
NpDtype,
TimestampNonexistent,
TimeUnit,
)
NaT: NaTType
iNaT: int
nat_strings: set[str]
_NaTComparisonTypes: TypeAlias = (
datetime | timedelta | Period | np.datetime64 | np.timedelta64
)
class _NatComparison:
def __call__(self, other: _NaTComparisonTypes) -> bool: ...
class NaTType:
value: np.int64
def __hash__(self) -> int: ...
def asm8(self) -> np.datetime64: ...
def to_datetime64(self) -> np.datetime64: ...
def to_numpy(
self, dtype: NpDtype | None = ..., copy: bool = ...
) -> np.datetime64 | np.timedelta64: ...
@property
def is_leap_year(self) -> bool: ...
@property
def is_month_start(self) -> bool: ...
@property
def is_quarter_start(self) -> bool: ...
@property
def is_year_start(self) -> bool: ...
@property
def is_month_end(self) -> bool: ...
@property
def is_quarter_end(self) -> bool: ...
@property
def is_year_end(self) -> bool: ...
@property
def day_of_year(self) -> float: ...
@property
def dayofyear(self) -> float: ...
@property
def days_in_month(self) -> float: ...
@property
def daysinmonth(self) -> float: ...
@property
def day_of_week(self) -> float: ...
@property
def dayofweek(self) -> float: ...
@property
def week(self) -> float: ...
@property
def weekofyear(self) -> float: ...
def day_name(self) -> float: ...
def month_name(self) -> float: ...
def weekday(self) -> float: ...
def isoweekday(self) -> float: ...
def total_seconds(self) -> float: ...
def today(self, tz: _tzinfo | str | None = None) -> NaTType: ...
def now(self, tz: _tzinfo | str | None = None) -> NaTType: ...
def to_pydatetime(self) -> NaTType: ...
def date(self) -> NaTType: ...
def round(
self,
freq: Frequency,
ambiguous: bool | Literal["raise"] | NaTType = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> NaTType: ...
def floor(
self,
freq: Frequency,
ambiguous: bool | Literal["raise"] | NaTType = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> NaTType: ...
def ceil(
self,
freq: Frequency,
ambiguous: bool | Literal["raise"] | NaTType = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> NaTType: ...
def tz_convert(self) -> NaTType: ...
def tz_localize(
self,
tz: _tzinfo | str | None,
ambiguous: bool | Literal["raise"] | NaTType = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> NaTType: ...
def replace(
self,
year: int | None = ...,
month: int | None = ...,
day: int | None = ...,
hour: int | None = ...,
minute: int | None = ...,
second: int | None = ...,
microsecond: int | None = ...,
nanosecond: int | None = ...,
tzinfo: _tzinfo | None = ...,
fold: int | None = ...,
) -> NaTType: ...
@property
def year(self) -> float: ...
@property
def quarter(self) -> float: ...
@property
def month(self) -> float: ...
@property
def day(self) -> float: ...
@property
def hour(self) -> float: ...
@property
def minute(self) -> float: ...
@property
def second(self) -> float: ...
@property
def millisecond(self) -> float: ...
@property
def microsecond(self) -> float: ...
@property
def nanosecond(self) -> float: ...
# inject Timedelta properties
@property
def days(self) -> float: ...
@property
def microseconds(self) -> float: ...
@property
def nanoseconds(self) -> float: ...
# inject Period properties
@property
def qyear(self) -> float: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
__lt__: _NatComparison
__le__: _NatComparison
__gt__: _NatComparison
__ge__: _NatComparison
@property
def unit(self) -> TimeUnit: ...
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self: ...

View File

@ -0,0 +1,2 @@
class OutOfBoundsDatetime(ValueError): ...
class OutOfBoundsTimedelta(ValueError): ...

View File

@ -0,0 +1,255 @@
from collections.abc import Collection
from datetime import (
date,
datetime,
time,
timedelta,
)
from typing import (
Any,
Literal,
TypeVar,
overload,
)
from dateutil.relativedelta import weekday as WeekdayClass
import numpy as np
from pandas import Timestamp
from typing_extensions import Self
from pandas._typing import npt
from pandas.tseries.holiday import AbstractHolidayCalendar
_DatetimeT = TypeVar("_DatetimeT", bound=datetime)
_TimedeltaT = TypeVar("_TimedeltaT", bound=timedelta)
class ApplyTypeError(TypeError): ...
class BaseOffset:
n: int
def __init__(self, n: int = ..., normalize: bool = ...) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
@property
def kwds(self) -> dict[str, Any]: ...
@property
def base(self) -> BaseOffset: ...
@overload
def __add__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
@overload
def __add__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __add__(self, other: date) -> Timestamp: ...
@overload
def __add__(self, other: BaseOffset) -> Self: ...
@overload
def __add__(self, other: _TimedeltaT) -> _TimedeltaT: ...
@overload
def __radd__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
@overload
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __radd__(self, other: date) -> Timestamp: ...
@overload
def __radd__(self, other: BaseOffset) -> Self: ...
@overload
def __radd__(self, other: _TimedeltaT) -> _TimedeltaT: ...
def __sub__(self, other: BaseOffset) -> Self: ...
@overload
def __rsub__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
@overload
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __rsub__(self, other: date) -> Timestamp: ...
@overload
def __rsub__(self, other: BaseOffset) -> Self: ...
@overload
def __rsub__(self, other: _TimedeltaT) -> _TimedeltaT: ...
@overload
def __mul__(self, other: np.ndarray) -> np.ndarray: ...
@overload
def __mul__(self, other: int) -> Self: ...
@overload
def __rmul__(self, other: np.ndarray) -> np.ndarray: ...
@overload
def __rmul__(self, other: int) -> Self: ...
def __neg__(self) -> Self: ...
def copy(self) -> Self: ...
@property
def name(self) -> str: ...
@property
def rule_code(self) -> str: ...
@property
def freqstr(self) -> str: ...
def rollback(self, dt: datetime) -> datetime: ...
def rollforward(self, dt: datetime) -> datetime: ...
def is_on_offset(self, dt: datetime) -> bool: ...
@property
def nanos(self) -> int: ...
class SingleConstructorOffset(BaseOffset): ...
class Tick(SingleConstructorOffset):
def __init__(self, n: int = ..., normalize: bool = ...) -> None: ...
@property
def nanos(self) -> int: ...
class Day(Tick): ...
class Hour(Tick): ...
class Minute(Tick): ...
class Second(Tick): ...
class Milli(Tick): ...
class Micro(Tick): ...
class Nano(Tick): ...
class RelativeDeltaOffset(BaseOffset):
def __init__(self, n: int = ..., normalize: bool = ..., **kwds: Any) -> None: ...
# Changed from implementation because it is not allowed for `PeriodDtype`
class BusinessDay(BaseOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., offset: timedelta = ...
) -> None: ...
def __reduce__(self): ...
class BusinessHour(SingleConstructorOffset):
def __init__(
self,
n: int = ...,
normalize: bool = ...,
start: str | time | Collection[str | time] = ...,
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
) -> None: ...
class WeekOfMonthMixin(SingleConstructorOffset):
def __init__(
self, n: int = ..., weekday: Literal[0, 1, 2, 3, 4, 5, 6] = ...
) -> None: ...
class YearOffset(SingleConstructorOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., month: int | None = ...
) -> None: ...
class BYearEnd(YearOffset): ...
class BYearBegin(YearOffset): ...
class YearEnd(YearOffset): ...
class YearBegin(YearOffset): ...
class QuarterOffset(SingleConstructorOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., startingMonth: int | None = ...
) -> None: ...
class BQuarterEnd(QuarterOffset): ...
class BQuarterBegin(QuarterOffset): ...
class QuarterEnd(QuarterOffset): ...
class QuarterBegin(QuarterOffset): ...
class MonthOffset(SingleConstructorOffset): ...
class MonthEnd(MonthOffset): ...
class MonthBegin(MonthOffset): ...
class BusinessMonthEnd(MonthOffset): ...
class BusinessMonthBegin(MonthOffset): ...
class SemiMonthOffset(SingleConstructorOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., day_of_month: int | None = ...
) -> None: ...
class SemiMonthEnd(SemiMonthOffset): ...
class SemiMonthBegin(SemiMonthOffset): ...
class Week(SingleConstructorOffset):
def __init__(
self, n: int = ..., normalize: bool = ..., weekday: int | None = ...
) -> None: ...
class WeekOfMonth(WeekOfMonthMixin):
def __init__(
self, n: int = ..., normalize: bool = ..., week: int = ..., weekday: int = ...
) -> None: ...
class LastWeekOfMonth(WeekOfMonthMixin): ...
class FY5253Mixin(SingleConstructorOffset):
def __init__(
self,
n: int = ...,
normalize: bool = ...,
weekday: int = ...,
startingMonth: int = ...,
variation: str = ...,
) -> None: ...
class FY5253(FY5253Mixin): ...
class FY5253Quarter(FY5253Mixin): ...
class Easter(SingleConstructorOffset): ...
class _CustomBusinessMonth(SingleConstructorOffset):
def __init__(
self,
n: int = ...,
normalize: bool = ...,
offset: timedelta = ...,
holidays: list | None = ...,
) -> None: ...
class CustomBusinessDay(BusinessDay):
def __init__(
self,
n: int = ...,
normalize: bool = ...,
holidays: list = ...,
calendar: AbstractHolidayCalendar | np.busdaycalendar = ...,
) -> None: ...
class CustomBusinessHour(BusinessHour):
def __init__(
self,
n: int = ...,
normalize: bool = ...,
start: str | time | Collection[str | time] = ...,
end: str | time | Collection[str | time] = ...,
offset: timedelta = ...,
holidays: list | None = ...,
) -> None: ...
class CustomBusinessMonthEnd(_CustomBusinessMonth): ...
class CustomBusinessMonthBegin(_CustomBusinessMonth): ...
class DateOffset(RelativeDeltaOffset):
def __init__(
self,
*,
n: int = ...,
normalize: bool = ...,
years: int = ...,
months: int = ...,
weeks: int = ...,
days: int = ...,
hours: int = ...,
minutes: int = ...,
seconds: int = ...,
milliseconds: int = ...,
microseconds: int = ...,
nanoseconds: int = ...,
year: int = ...,
month: int = ...,
day: int = ...,
weekday: int | WeekdayClass = ...,
hour: int = ...,
minute: int = ...,
second: int = ...,
microsecond: int = ...,
nanosecond: int = ...,
) -> None: ...
BDay = BusinessDay
BMonthEnd = BusinessMonthEnd
BMonthBegin = BusinessMonthBegin
CBMonthEnd = CustomBusinessMonthEnd
CBMonthBegin = CustomBusinessMonthBegin
CDay = CustomBusinessDay

View File

@ -0,0 +1,2 @@
class DateParseError(ValueError):
def __init__(self, *args, **kwargs) -> None: ...

View File

@ -0,0 +1,232 @@
import datetime
from typing import (
Literal,
overload,
)
import numpy as np
from pandas import (
Index,
PeriodIndex,
Series,
Timedelta,
TimedeltaIndex,
)
from pandas.core.series import (
OffsetSeries,
PeriodSeries,
TimedeltaSeries,
)
from typing_extensions import TypeAlias
from pandas._libs.tslibs import NaTType
from pandas._libs.tslibs.offsets import BaseOffset
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
ShapeT,
np_1darray,
np_ndarray,
)
class IncompatibleFrequency(ValueError): ...
_PeriodAddSub: TypeAlias = (
Timedelta | datetime.timedelta | np.timedelta64 | np.int64 | int | BaseOffset
)
_PeriodFreqHow: TypeAlias = Literal[
"S",
"E",
"start",
"end",
]
_PeriodToTimestampHow: TypeAlias = (
_PeriodFreqHow
| Literal[
"Start",
"Finish",
"Begin",
"End",
"s",
"e",
"finish",
"begin",
]
)
class PeriodMixin:
@property
def end_time(self) -> Timestamp: ...
@property
def start_time(self) -> Timestamp: ...
class Period(PeriodMixin):
def __init__(
self,
value: (
Period | str | datetime.datetime | datetime.date | Timestamp | None
) = ...,
freq: str | BaseOffset | None = ...,
ordinal: int | None = ...,
year: int | None = ...,
month: int | None = ...,
quarter: int | None = ...,
day: int | None = ...,
hour: int | None = ...,
minute: int | None = ...,
second: int | None = ...,
) -> None: ...
@overload
def __sub__(self, other: _PeriodAddSub) -> Period: ...
@overload
def __sub__(self, other: Period) -> BaseOffset: ...
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
def __sub__(self, other: PeriodIndex) -> Index: ...
@overload
def __sub__(self, other: TimedeltaSeries) -> PeriodSeries: ...
@overload
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
@overload
def __add__(self, other: _PeriodAddSub) -> Period: ...
@overload
def __add__(self, other: NaTType) -> NaTType: ...
@overload
def __add__(self, other: Index) -> PeriodIndex: ...
@overload
def __add__(self, other: OffsetSeries | TimedeltaSeries) -> PeriodSeries: ...
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: np_ndarray[ShapeT, np.object_]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ge__(self, other: Period) -> bool: ...
@overload
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __ge__(self, other: PeriodSeries) -> Series[bool]: ...
@overload
def __ge__(
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __gt__(self, other: Period) -> bool: ...
@overload
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __gt__(self, other: PeriodSeries) -> Series[bool]: ...
@overload
def __gt__(
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __le__(self, other: Period) -> bool: ...
@overload
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __le__(self, other: PeriodSeries) -> Series[bool]: ...
@overload
def __le__(
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __lt__(self, other: Period) -> bool: ...
@overload
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
def __lt__(self, other: PeriodSeries) -> Series[bool]: ...
@overload
def __lt__(
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: np_ndarray[ShapeT, np.object_]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: object) -> Literal[True]: ...
# Ignored due to indecipherable error from mypy:
# Forward operator "__add__" is not callable [misc]
@overload
def __radd__(self, other: _PeriodAddSub) -> Period: ... # type: ignore[misc]
# Real signature is -> PeriodIndex, but conflicts with Index.__add__
# Changing Index is very hard due to Index inheritance
# Signatures of "__radd__" of "Period" and "__add__" of "Index"
# are unsafely overlapping
@overload
def __radd__(self, other: Index) -> Index: ...
@overload
def __radd__(self, other: TimedeltaSeries) -> PeriodSeries: ...
@overload
def __radd__(self, other: NaTType) -> NaTType: ...
@property
def day(self) -> int: ...
@property
def dayofweek(self) -> int: ...
@property
def dayofyear(self) -> int: ...
@property
def daysinmonth(self) -> int: ...
@property
def days_in_month(self) -> int: ...
@property
def end_time(self) -> Timestamp: ...
@property
def freq(self) -> BaseOffset: ...
@property
def freqstr(self) -> str: ...
@property
def hour(self) -> int: ...
@property
def minute(self) -> int: ...
@property
def month(self) -> int: ...
@property
def quarter(self) -> int: ...
@property
def qyear(self) -> int: ...
@property
def second(self) -> int: ...
@property
def ordinal(self) -> int: ...
@property
def is_leap_year(self) -> bool: ...
@property
def start_time(self) -> Timestamp: ...
@property
def week(self) -> int: ...
@property
def weekday(self) -> int: ...
@property
def weekofyear(self) -> int: ...
@property
def year(self) -> int: ...
@property
def day_of_year(self) -> int: ...
@property
def day_of_week(self) -> int: ...
def asfreq(self, freq: str | BaseOffset, how: _PeriodFreqHow = "end") -> Period: ...
@classmethod
def now(cls, freq: str | BaseOffset = ...) -> Period: ...
def strftime(self, fmt: str) -> str: ...
def to_timestamp(
self,
freq: str | BaseOffset | None = ...,
how: _PeriodToTimestampHow = "S",
) -> Timestamp: ...

View File

@ -0,0 +1,406 @@
# pyright: strict
import datetime as dt
from datetime import timedelta
from typing import (
ClassVar,
Literal,
NamedTuple,
overload,
)
import numpy as np
import pandas as pd
from pandas import (
DatetimeIndex,
Index,
PeriodIndex,
Series,
TimedeltaIndex,
)
from pandas.core.series import (
TimedeltaSeries,
TimestampSeries,
)
from typing_extensions import (
Self,
TypeAlias,
)
from pandas._libs.tslibs import (
BaseOffset,
NaTType,
)
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
ShapeT,
TimeUnit,
np_1darray,
np_ndarray,
npt,
)
class Components(NamedTuple):
days: int
hours: int
minutes: int
seconds: int
milliseconds: int
microseconds: int
nanoseconds: int
# This should be kept consistent with the keys in the dict timedelta_abbrevs
# in pandas/_libs/tslibs/timedeltas.pyx
TimeDeltaUnitChoices: TypeAlias = Literal[
"W",
"w",
"D",
"d",
"days",
"day",
"hours",
"hour",
"hr",
"h",
"m",
"minute",
"min",
"minutes",
"s",
"seconds",
"sec",
"second",
"ms",
"milliseconds",
"millisecond",
"milli",
"millis",
"us",
"microseconds",
"microsecond",
"µs",
"micro",
"micros",
"ns",
"nanoseconds",
"nano",
"nanos",
"nanosecond",
]
UnitChoices: TypeAlias = (
TimeDeltaUnitChoices
| Literal[
"Y",
"y",
"M",
]
)
class Timedelta(timedelta):
min: ClassVar[Timedelta] # pyright: ignore[reportIncompatibleVariableOverride]
max: ClassVar[Timedelta] # pyright: ignore[reportIncompatibleVariableOverride]
resolution: ClassVar[ # pyright: ignore[reportIncompatibleVariableOverride]
Timedelta
]
value: int
def __new__(
cls,
value: str | float | Timedelta | timedelta | np.timedelta64 = ...,
unit: TimeDeltaUnitChoices = ...,
*,
days: float | np.integer | np.floating = ...,
seconds: float | np.integer | np.floating = ...,
microseconds: float | np.integer | np.floating = ...,
milliseconds: float | np.integer | np.floating = ...,
minutes: float | np.integer | np.floating = ...,
hours: float | np.integer | np.floating = ...,
weeks: float | np.integer | np.floating = ...,
) -> Self: ...
# GH 46171
# While Timedelta can return pd.NaT, having the constructor return
# a Union with NaTType makes things awkward for users of pandas
@property
def days(self) -> int: ...
@property
def nanoseconds(self) -> int: ...
@property
def seconds(self) -> int: ...
@property
def microseconds(self) -> int: ...
def total_seconds(self) -> float: ...
def to_pytimedelta(self) -> timedelta: ...
def to_timedelta64(self) -> np.timedelta64: ...
@property
def asm8(self) -> np.timedelta64: ...
# TODO: round/floor/ceil could return NaT?
def round(self, freq: str | BaseOffset) -> Self: ...
def floor(self, freq: str | BaseOffset) -> Self: ...
def ceil(self, freq: str | BaseOffset) -> Self: ...
@property
def resolution_string(self) -> str: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __add__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __add__(self, other: dt.datetime | np.datetime64 | Timestamp) -> Timestamp: ...
@overload
def __add__(self, other: NaTType) -> NaTType: ...
@overload
def __add__(self, other: Period) -> Period: ...
@overload
def __add__(self, other: dt.date) -> dt.date: ...
@overload
def __add__(self, other: PeriodIndex) -> PeriodIndex: ...
@overload
def __add__(self, other: DatetimeIndex) -> DatetimeIndex: ...
@overload
def __add__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __add__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
@overload
def __add__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
@overload
def __add__(
self,
other: TimedeltaSeries,
) -> TimedeltaSeries: ...
@overload
def __add__(self, other: TimestampSeries) -> TimestampSeries: ...
@overload
def __radd__(self, other: np.datetime64) -> Timestamp: ...
@overload
def __radd__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __radd__(self, other: NaTType) -> NaTType: ...
@overload
def __radd__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __radd__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
@overload
def __radd__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
@overload
def __radd__(self, other: pd.PeriodIndex) -> pd.PeriodIndex: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __sub__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
def __sub__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __sub__(self, other: pd.TimedeltaIndex) -> TimedeltaIndex: ...
@overload
def __sub__(
self, other: TimedeltaSeries | Series[pd.Timedelta]
) -> TimedeltaSeries: ...
@overload
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __rsub__(self, other: dt.datetime | Timestamp | np.datetime64) -> Timestamp: ... # type: ignore[misc]
@overload
def __rsub__(self, other: NaTType) -> NaTType: ...
@overload
def __rsub__(self, other: Period) -> Period: ...
@overload
def __rsub__(self, other: PeriodIndex) -> PeriodIndex: ...
@overload
def __rsub__(self, other: DatetimeIndex) -> DatetimeIndex: ...
@overload
def __rsub__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
@overload
def __rsub__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __rsub__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
def __neg__(self) -> Timedelta: ...
def __pos__(self) -> Timedelta: ...
def __abs__(self) -> Timedelta: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __mul__(self, other: float) -> Timedelta: ...
@overload
def __mul__(
self, other: np_ndarray[ShapeT, np.integer] | np_ndarray[ShapeT, np.floating]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __mul__(self, other: Series[int]) -> TimedeltaSeries: ...
@overload
def __mul__(self, other: Series[float]) -> TimedeltaSeries: ...
@overload
def __mul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
@overload
def __rmul__(self, other: float) -> Timedelta: ...
@overload
def __rmul__(
self, other: np_ndarray[ShapeT, np.floating] | np_ndarray[ShapeT, np.integer]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __rmul__(self, other: Series[int]) -> TimedeltaSeries: ...
@overload
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
# maybe related to https://github.com/python/mypy/issues/10755
@overload
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
# Override due to more types supported than dt.timedelta
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
@overload # type: ignore[override]
def __floordiv__(self, other: timedelta | Timedelta | np.timedelta64) -> int: ...
@overload
def __floordiv__(self, other: float) -> Timedelta: ...
@overload
def __floordiv__(
self, other: np_ndarray[ShapeT, np.integer] | np_ndarray[ShapeT, np.floating]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __floordiv__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.int_]: ...
@overload
def __floordiv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
@overload
def __floordiv__(self, other: Series[int]) -> TimedeltaSeries: ...
@overload
def __floordiv__(self, other: Series[float]) -> TimedeltaSeries: ...
@overload
def __floordiv__(self, other: TimedeltaSeries) -> Series[int]: ...
@overload
def __floordiv__(self, other: NaTType | None) -> float: ...
@overload
def __rfloordiv__(self, other: timedelta | Timedelta | str) -> int: ...
@overload
def __rfloordiv__(self, other: NaTType | None) -> float: ...
@overload
def __rfloordiv__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.int_]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __truediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
@overload
def __truediv__(self, other: float) -> Timedelta: ...
@overload
def __truediv__(
self, other: np_ndarray[ShapeT, np.integer] | np_ndarray[ShapeT, np.floating]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __truediv__(self, other: TimedeltaSeries) -> Series[float]: ...
@overload
def __truediv__(self, other: Series[int]) -> TimedeltaSeries: ...
@overload
def __truediv__(self, other: Series[float]) -> TimedeltaSeries: ...
@overload
def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
# Override due to more types supported than dt.timedelta
@overload
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__( # type: ignore[overload-overlap]
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __eq__(self, other: object) -> Literal[False]: ...
# Override due to more types supported than dt.timedelta
@overload
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__( # type: ignore[overload-overlap]
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __ne__(self, other: object) -> Literal[True]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __mod__(self, other: timedelta) -> Timedelta: ...
@overload
def __mod__(self, other: float) -> Timedelta: ...
@overload
def __mod__(self, other: Series[int] | Series[float]) -> TimedeltaSeries: ...
@overload
def __mod__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
@overload
def __mod__(
self, other: np_ndarray[ShapeT, np.integer] | np_ndarray[ShapeT, np.floating]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __mod__(
self, other: Series[int] | Series[float] | TimedeltaSeries
) -> TimedeltaSeries: ...
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
# for le, lt ge and gt
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __le__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __le__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __le__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __le__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __lt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __lt__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __lt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __ge__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __ge__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __ge__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __gt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __gt__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __gt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
def __hash__(self) -> int: ...
def isoformat(self) -> str: ...
def to_numpy(self) -> np.timedelta64: ...
@property
def components(self) -> Components: ...
def view(self, dtype: npt.DTypeLike = ...) -> object: ...
@property
def unit(self) -> TimeUnit: ...
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self: ...

View File

@ -0,0 +1,352 @@
# pyright: strict
from datetime import (
date as _date,
datetime,
time as _time,
timedelta,
tzinfo as _tzinfo,
)
from datetime import _IsoCalendarDate # pyright: ignore[reportPrivateUsage]
import sys
from time import struct_time
from typing import (
ClassVar,
Literal,
SupportsIndex,
overload,
)
import numpy as np
from pandas import (
DatetimeIndex,
TimedeltaIndex,
)
from pandas.core.indexes.base import Index
from pandas.core.series import (
Series,
TimedeltaSeries,
TimestampSeries,
)
from typing_extensions import (
Never,
Self,
TypeAlias,
)
from pandas._libs.tslibs import (
BaseOffset,
Period,
Tick,
Timedelta,
)
from pandas._typing import (
ShapeT,
TimestampNonexistent,
TimeUnit,
np_1darray,
np_ndarray,
)
_Ambiguous: TypeAlias = bool | Literal["raise", "NaT"]
# Repeated from `_typing.pyi` so as to satisfy mixed strict / non-strict paths.
# https://github.com/pandas-dev/pandas-stubs/pull/1151#issuecomment-2715130190
TimeZones: TypeAlias = str | _tzinfo | None | int
class Timestamp(datetime, SupportsIndex):
min: ClassVar[Timestamp] # pyright: ignore[reportIncompatibleVariableOverride]
max: ClassVar[Timestamp] # pyright: ignore[reportIncompatibleVariableOverride]
resolution: ClassVar[ # pyright: ignore[reportIncompatibleVariableOverride]
Timedelta
]
value: int
def __new__(
cls,
ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ...,
year: int | None = ...,
month: int | None = ...,
day: int | None = ...,
hour: int | None = ...,
minute: int | None = ...,
second: int | None = ...,
microsecond: int | None = ...,
tzinfo: _tzinfo | None = ...,
*,
nanosecond: int | None = ...,
tz: TimeZones = ...,
unit: str | int | None = ...,
fold: Literal[0, 1] | None = ...,
) -> Self: ...
# GH 46171
# While Timestamp can return pd.NaT, having the constructor return
# a Union with NaTType makes things awkward for users of pandas
@property
def year(self) -> int: ...
@property
def month(self) -> int: ...
@property
def day(self) -> int: ...
@property
def hour(self) -> int: ...
@property
def minute(self) -> int: ...
@property
def second(self) -> int: ...
@property
def microsecond(self) -> int: ...
@property
def nanosecond(self) -> int: ...
@property
def tzinfo(self) -> _tzinfo | None: ...
@property
def tz(self) -> _tzinfo | None: ...
@property
def fold(self) -> int: ...
if sys.version_info >= (3, 12):
@classmethod
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore
cls, t: float, tz: _tzinfo | str | None = ...
) -> Self: ...
else:
@classmethod
def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ...
@classmethod
def utcfromtimestamp(cls, ts: float) -> Self: ...
@classmethod
def today(cls, tz: _tzinfo | str | None = None) -> Self: ...
@classmethod
def fromordinal(
cls,
ordinal: int,
tz: _tzinfo | str | None = ...,
) -> Self: ...
@classmethod
def now(cls, tz: _tzinfo | str | None = None) -> Self: ...
@classmethod
def utcnow(cls) -> Self: ...
# error: Signature of "combine" incompatible with supertype "datetime"
@classmethod
def combine(cls, date: _date, time: _time) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@classmethod
def fromisoformat(cls, date_string: str) -> Self: ...
def strftime(self, format: str) -> str: ...
def __format__(self, fmt: str) -> str: ...
def toordinal(self) -> int: ...
def timetuple(self) -> struct_time: ...
def timestamp(self) -> float: ...
def utctimetuple(self) -> struct_time: ...
def date(self) -> _date: ...
def time(self) -> _time: ...
def timetz(self) -> _time: ...
# Override since fold is more precise than datetime.replace(fold:int)
# Here it is restricted to be 0 or 1 using a Literal
# Violation of Liskov substitution principle
def replace( # type:ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore
self,
year: int | None = ...,
month: int | None = ...,
day: int | None = ...,
hour: int | None = ...,
minute: int | None = ...,
second: int | None = ...,
microsecond: int | None = ...,
tzinfo: _tzinfo | None = ...,
fold: Literal[0, 1] | None = ...,
) -> Timestamp: ...
def astimezone(self, tz: _tzinfo | None = ...) -> Self: ...
def ctime(self) -> str: ...
def isoformat( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self,
sep: str = "T",
timespec: Literal[
"auto",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
] = "auto",
) -> str: ...
@classmethod
def strptime(cls, date_string: Never, format: Never) -> Never: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def utcoffset(self) -> timedelta | None: ...
def tzname(self) -> str | None: ...
def dst(self) -> timedelta | None: ...
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
# for le, lt ge and gt
@overload # type: ignore[override]
def __le__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __le__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
def __le__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __le__(self, other: TimestampSeries) -> Series[bool]: ...
@overload # type: ignore[override]
def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __lt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
def __lt__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __lt__(self, other: TimestampSeries) -> Series[bool]: ...
@overload # type: ignore[override]
def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __ge__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
def __ge__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __ge__(self, other: TimestampSeries) -> Series[bool]: ...
@overload # type: ignore[override]
def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __gt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
def __gt__(
self, other: np_ndarray[ShapeT, np.datetime64]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __gt__(self, other: TimestampSeries) -> Series[bool]: ...
# error: Signature of "__add__" incompatible with supertype "date"/"datetime"
@overload # type: ignore[override]
def __add__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
@overload
def __add__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
@overload
def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ...
@overload
def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
@overload
def __radd__(self, other: timedelta) -> Self: ...
@overload
def __radd__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
@overload
def __radd__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
# TODO: test dt64
@overload # type: ignore[override]
def __sub__(self, other: Timestamp | datetime | np.datetime64) -> Timedelta: ...
@overload
def __sub__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
@overload
def __sub__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
@overload
def __sub__(self, other: TimedeltaSeries) -> TimestampSeries: ...
@overload
def __sub__(self, other: TimestampSeries) -> TimedeltaSeries: ...
@overload
def __sub__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
@overload
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: np_ndarray[ShapeT, np.datetime64]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: np_ndarray[ShapeT, np.datetime64]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: object) -> Literal[True]: ...
def __hash__(self) -> int: ...
def weekday(self) -> int: ...
def isoweekday(self) -> int: ...
def isocalendar(self) -> _IsoCalendarDate: ...
@property
def is_leap_year(self) -> bool: ...
@property
def is_month_start(self) -> bool: ...
@property
def is_quarter_start(self) -> bool: ...
@property
def is_year_start(self) -> bool: ...
@property
def is_month_end(self) -> bool: ...
@property
def is_quarter_end(self) -> bool: ...
@property
def is_year_end(self) -> bool: ...
def to_pydatetime(self, warn: bool = ...) -> datetime: ...
def to_datetime64(self) -> np.datetime64: ...
def to_period(self, freq: BaseOffset | str | None = ...) -> Period: ...
def to_julian_date(self) -> np.float64: ...
@property
def asm8(self) -> np.datetime64: ...
def tz_convert(self, tz: TimeZones) -> Self: ...
# TODO: could return NaT?
def tz_localize(
self,
tz: TimeZones,
ambiguous: _Ambiguous = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> Self: ...
def normalize(self) -> Self: ...
# TODO: round/floor/ceil could return NaT?
def round(
self,
freq: str,
ambiguous: _Ambiguous = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> Self: ...
def floor(
self,
freq: str,
ambiguous: _Ambiguous = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> Self: ...
def ceil(
self,
freq: str,
ambiguous: _Ambiguous = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> Self: ...
def day_name(self, locale: str | None = None) -> str: ...
def month_name(self, locale: str | None = None) -> str: ...
@property
def day_of_week(self) -> int: ...
@property
def dayofweek(self) -> int: ...
@property
def day_of_year(self) -> int: ...
@property
def dayofyear(self) -> int: ...
@property
def weekofyear(self) -> int: ...
@property
def quarter(self) -> int: ...
@property
def week(self) -> int: ...
def to_numpy(self) -> np.datetime64: ...
@property
def days_in_month(self) -> int: ...
@property
def daysinmonth(self) -> int: ...
@property
def unit(self) -> TimeUnit: ...
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self: ...
# To support slicing
def __index__(self) -> int: ...