Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:
autofix_prs: false
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.3
rev: v0.14.0
hooks:
- id: ruff-check
args: [--exit-non-zero-on-fix]
Expand Down
38 changes: 13 additions & 25 deletions pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ from typing import (
)

import numpy as np
from pandas import (
Index,
PeriodIndex,
Series,
Timedelta,
TimedeltaIndex,
)
from pandas.core.indexes.base import Index
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.tslibs import NaTType
from pandas._libs.tslibs.offsets import (
BaseOffset,
)
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
PeriodFrequency,
Expand Down Expand Up @@ -79,7 +77,7 @@ class Period(PeriodMixin):
@overload
def __sub__(self, other: _PeriodAddSub) -> Period: ...
@overload
def __sub__(self, other: Period) -> BaseOffset: ...
def __sub__(self, other: Self) -> BaseOffset: ...
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
Expand All @@ -95,23 +93,13 @@ class Period(PeriodMixin):
@overload
def __add__(self, other: NaTType) -> NaTType: ...
@overload
def __add__(self, other: Index) -> PeriodIndex: ...
# Ignored due to indecipherable error from mypy:
# Forward operator "__add__" is not callable [misc]
@overload
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc,unused-ignore]
@overload
def __radd__(self, other: NaTType) -> NaTType: ...
# 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) -> PeriodIndex: ...
# 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]
def __eq__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -121,7 +109,7 @@ class Period(PeriodMixin):
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ge__(self, other: Period) -> bool: ...
def __ge__(self, other: Self) -> bool: ...
@overload
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -133,7 +121,7 @@ class Period(PeriodMixin):
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __gt__(self, other: Period) -> bool: ...
def __gt__(self, other: Self) -> bool: ...
@overload
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -145,7 +133,7 @@ class Period(PeriodMixin):
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __le__(self, other: Period) -> bool: ...
def __le__(self, other: Self) -> bool: ...
@overload
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -157,7 +145,7 @@ class Period(PeriodMixin):
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __lt__(self, other: Period) -> bool: ...
def __lt__(self, other: Self) -> bool: ...
@overload
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -171,7 +159,7 @@ class Period(PeriodMixin):
# 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]
def __ne__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down
67 changes: 33 additions & 34 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ from typing import (
)

import numpy as np
import pandas as pd
from pandas import (
DatetimeIndex,
Index,
PeriodIndex,
Series,
TimedeltaIndex,
)
from numpy import typing as npt
from pandas.core.indexes.base import Index
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.tslibs import (
Expand All @@ -35,7 +33,6 @@ from pandas._typing import (
TimeUnit,
np_1darray,
np_ndarray,
npt,
)

class Components(NamedTuple):
Expand Down Expand Up @@ -174,17 +171,17 @@ class Timedelta(timedelta):
) -> np_ndarray[ShapeT, np.datetime64]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __sub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
def __sub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
@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: ...
def __sub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
@overload
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
def __rsub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
@overload
def __rsub__(self, other: datetime | Timestamp | np.datetime64) -> Timestamp: ... # type: ignore[misc]
@overload
Expand All @@ -204,7 +201,7 @@ class Timedelta(timedelta):
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __rsub__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
def __rsub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
def __neg__(self) -> Self: ...
def __pos__(self) -> Self: ...
def __abs__(self) -> Self: ...
Expand All @@ -224,7 +221,7 @@ class Timedelta(timedelta):
# Override due to more types supported than timedelta
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
@overload # type: ignore[override]
def __floordiv__(self, other: timedelta | Timedelta | np.timedelta64) -> int: ...
def __floordiv__(self, other: timedelta | np.timedelta64 | Self) -> int: ...
@overload
def __floordiv__(self, other: float) -> Self: ...
@overload
Expand Down Expand Up @@ -255,27 +252,29 @@ class Timedelta(timedelta):
) -> np_ndarray[ShapeT, np.int_]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __truediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
# pyrefly: ignore[bad-override]
def __truediv__(self, other: Just[int] | Just[float]) -> Self: ...
@overload
def __truediv__(self, other: float) -> Self: ...
def __truediv__(self, other: Self | NaTType) -> float: ...
@overload
def __truediv__(
self, other: np_ndarray[ShapeT, np.integer | np.floating]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __truediv__(self, other: Series[Timedelta]) -> Series[float]: ...
@overload
def __truediv__(self, other: Series[int]) -> Series[Timedelta]: ...
def __truediv__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.floating]: ...
@overload
def __truediv__(self, other: Series[float]) -> Series[Timedelta]: ...
def __rtruediv__(self, other: Self | NaTType) -> float: ...
@overload
def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
def __rtruediv__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.floating]: ...
# Override due to more types supported than timedelta
@overload
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __eq__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
def __eq__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -286,9 +285,9 @@ class Timedelta(timedelta):
def __eq__(self, other: object) -> Literal[False]: ...
# Override due to more types supported than timedelta
@overload
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __ne__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
def __ne__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down Expand Up @@ -319,48 +318,48 @@ class Timedelta(timedelta):
# for le, lt ge and gt
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __le__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __le__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@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: Series[pd.Timedelta]) -> Series[bool]: ...
def __le__(self, other: Series[Timedelta]) -> Series[bool]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __lt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@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: Series[pd.Timedelta]) -> Series[bool]: ...
def __lt__(self, other: Series[Timedelta]) -> Series[bool]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __ge__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@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: Series[pd.Timedelta]) -> Series[bool]: ...
def __ge__(self, other: Series[Timedelta]) -> Series[bool]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __gt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@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: Series[pd.Timedelta]) -> Series[bool]: ...
def __gt__(self, other: Series[Timedelta]) -> Series[bool]: ...
def __hash__(self) -> int: ...
def isoformat(self) -> str: ...
def to_numpy(self) -> np.timedelta64: ...
Expand Down
21 changes: 9 additions & 12 deletions pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ from typing import (
)

import numpy as np
from pandas import (
DatetimeIndex,
TimedeltaIndex,
)
from pandas.core.indexes.base import Index
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import (
Never,
Expand Down Expand Up @@ -99,10 +97,9 @@ class Timestamp(datetime, SupportsIndex):
def tz(self) -> _tzinfo | None: ...
@property
def fold(self) -> int: ...

if sys.version_info >= (3, 12):
@classmethod
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride]
cls, t: float, tz: _tzinfo | str | None = ...
) -> Self: ...
else:
Expand Down Expand Up @@ -175,7 +172,7 @@ class Timestamp(datetime, SupportsIndex):
# 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]
def __le__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __le__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -185,7 +182,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __le__(self, other: Series[Timestamp]) -> Series[bool]: ...
@overload # type: ignore[override]
def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __lt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __lt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -195,7 +192,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __lt__(self, other: Series[Timestamp]) -> Series[bool]: ...
@overload # type: ignore[override]
def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __ge__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __ge__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -205,7 +202,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __ge__(self, other: Series[Timestamp]) -> Series[bool]: ...
@overload # type: ignore[override]
def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __gt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __gt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand Down Expand Up @@ -243,7 +240,7 @@ class Timestamp(datetime, SupportsIndex):
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]
def __eq__(self, other: datetime | np.datetime64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -253,7 +250,7 @@ class Timestamp(datetime, SupportsIndex):
@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]
def __ne__(self, other: datetime | np.datetime64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down
10 changes: 10 additions & 0 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ from typing import (
overload,
)

from _typeshed import _T_contra
import numpy as np
from numpy import typing as npt
import pandas as pd
Expand Down Expand Up @@ -860,6 +861,9 @@ np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]
# Define shape and generic type variables with defaults similar to numpy
GenericT = TypeVar("GenericT", bound=np.generic, default=Any)
GenericT_co = TypeVar("GenericT_co", bound=np.generic, default=Any, covariant=True)
GenericT_contra = TypeVar(
"GenericT_contra", bound=np.generic, default=Any, contravariant=True
)
ShapeT = TypeVar("ShapeT", bound=tuple[int, ...], default=tuple[Any, ...])
# Numpy ndarray with more ergonomic typevar
np_ndarray: TypeAlias = np.ndarray[ShapeT, np.dtype[GenericT]]
Expand Down Expand Up @@ -1114,4 +1118,10 @@ class Just(Protocol, Generic[T]):
@override
def __class__(self, t: type[T], /) -> None: ...

class SupportsTrueDiv(Protocol[_T_contra, _T_co]):
def __truediv__(self, x: _T_contra, /) -> _T_co: ...

class SupportsRTrueDiv(Protocol[_T_contra, _T_co]):
def __rtruediv__(self, x: _T_contra, /) -> _T_co: ...

__all__ = ["npt", "type_t"]
Loading