Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 2 deletions pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ class Period(PeriodMixin):
@overload
def __radd__(self, other: Index) -> Index: ...
@overload
def __radd__(self, other: Series[Timedelta]) -> PeriodSeries: ...
@overload
def __radd__(self, other: NaTType) -> NaTType: ...
@property
def day(self) -> int: ...
Expand Down
24 changes: 6 additions & 18 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,16 @@ class Timedelta(timedelta):
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: ...
def __add__(self, other: dt.datetime | np.datetime64) -> Timestamp: ...
@overload
def __add__(self, other: dt.datetime | np.datetime64 | Timestamp) -> Timestamp: ...
def __add__(self, other: timedelta | np.timedelta64) -> Self: ...
@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]: ...
Expand All @@ -159,29 +155,21 @@ class Timedelta(timedelta):
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: Series[Timedelta]) -> Series[Timedelta]: ...
@overload
def __add__(self, other: Series[Timestamp]) -> Series[Timestamp]: ...
def __radd__(self, other: dt.datetime | np.datetime64) -> Timestamp: ... # type: ignore[misc]
@overload
def __radd__(self, other: np.datetime64) -> Timestamp: ...
@overload
def __radd__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
def __radd__(self, other: timedelta | np.timedelta64) -> Self: ...
@overload
def __radd__(self, other: NaTType) -> NaTType: ...
@overload
def __radd__(self, other: dt.date) -> dt.date: ...
@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: ...
Expand Down
18 changes: 13 additions & 5 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -847,25 +847,33 @@ MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]

T_INT = TypeVar("T_INT", bound=int)
T_COMPLEX = TypeVar("T_COMPLEX", bound=complex)
SeriesDType: TypeAlias = (
SeriesDTypeNoDateTime: TypeAlias = (
str
| bytes
| datetime.date
| datetime.time
| bool
| int
| float
| complex
| Dtype
| datetime.datetime # includes pd.Timestamp
| datetime.timedelta # includes pd.Timedelta
| Period
| Interval
| CategoricalDtype
| BaseOffset
| list[str]
)
SeriesDType: TypeAlias = (
SeriesDTypeNoDateTime
| datetime.date
| datetime.time
| datetime.datetime # includes pd.Timestamp
| datetime.timedelta # includes pd.Timedelta
)
S1 = TypeVar("S1", bound=SeriesDType, default=Any)
S1_CT_NDT = TypeVar(
"S1_CT_NDT", bound=SeriesDTypeNoDateTime, default=Any, contravariant=True
)
S1_CO = TypeVar("S1_CO", bound=SeriesDType, default=Any, covariant=True)
S1_CT = TypeVar("S1_CT", bound=SeriesDType, default=Any, contravariant=True)
# Like S1, but without `default=Any`.
S2 = TypeVar("S2", bound=SeriesDType)
S3 = TypeVar("S3", bound=SeriesDType)
Expand Down
126 changes: 45 additions & 81 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ from collections.abc import (
Callable,
Hashable,
Iterable,
Iterator,
Sequence,
)
from datetime import (
Expand All @@ -20,6 +19,10 @@ from typing import (
type_check_only,
)

from _typeshed import (
SupportsAdd,
SupportsRAdd,
)
import numpy as np
from pandas import (
DataFrame,
Expand Down Expand Up @@ -49,8 +52,9 @@ from pandas._libs.interval import _OrderableT
from pandas._typing import (
C2,
S1,
S1_CO,
S1_CT,
T_COMPLEX,
T_INT,
AnyAll,
ArrayLike,
AxesData,
Expand Down Expand Up @@ -471,7 +475,6 @@ class Index(IndexOpsMixin[S1]):
def shape(self) -> tuple[int, ...]: ...
# Extra methods from old stubs
def __eq__(self, other: object) -> np_1darray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __iter__(self) -> Iterator[S1]: ...
def __ne__(self, other: object) -> np_1darray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __le__(self, other: Self | S1) -> np_1darray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __ge__(self, other: Self | S1) -> np_1darray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
Expand All @@ -484,65 +487,43 @@ class Index(IndexOpsMixin[S1]):
@overload
def __add__(self, other: Index[Never]) -> Index: ...
@overload
def __add__(
self: Index[bool],
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX],
) -> Index[T_COMPLEX]: ...
@overload
def __add__(self: Index[bool], other: np_ndarray_bool) -> Index[bool]: ...
def __add__(self: Index[bool], other: bool | Sequence[bool]) -> Index[bool]: ...
@overload
def __add__(self: Index[bool], other: np_ndarray_anyint) -> Index[int]: ...
def __add__(self: Index[int], other: bool | Sequence[bool]) -> Index[int]: ...
@overload
def __add__(self: Index[bool], other: np_ndarray_float) -> Index[float]: ...
def __add__(self: Index[float], other: int | Sequence[int]) -> Index[float]: ...
@overload
def __add__(self: Index[bool], other: np_ndarray_complex) -> Index[complex]: ...
def __add__(
self: Index[complex], other: float | Sequence[float]
) -> Index[complex]: ...
@overload
def __add__(
self: Index[int],
other: (
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Index[bool]
),
) -> Index[int]: ...
self: Index[S1_CT],
other: SupportsRAdd[S1_CT, S1_CO] | Sequence[SupportsRAdd[S1_CT, S1_CO]],
) -> Index[S1_CO]: ...
@overload
def __add__(
self: Index[int],
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX],
self: Index[T_COMPLEX], other: np_ndarray_bool | Index[bool]
) -> Index[T_COMPLEX]: ...
@overload
def __add__(self: Index[int], other: np_ndarray_float) -> Index[float]: ...
def __add__(
self: Index[bool], other: np_ndarray_anyint | Index[int]
) -> Index[int]: ...
@overload
def __add__(self: Index[int], other: np_ndarray_complex) -> Index[complex]: ...
def __add__(
self: Index[T_COMPLEX], other: np_ndarray_anyint | Index[int]
) -> Index[T_COMPLEX]: ...
@overload
def __add__(
self: Index[float],
other: (
int
| Sequence[int]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[T_INT]
),
self: Index[bool] | Index[int], other: np_ndarray_float | Index[float]
) -> Index[float]: ...
@overload
def __add__(
self: Index[float],
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX],
self: Index[T_COMPLEX], other: np_ndarray_float | Index[float]
) -> Index[T_COMPLEX]: ...
@overload
def __add__(self: Index[float], other: np_ndarray_complex) -> Index[complex]: ...
@overload
def __add__(
self: Index[complex],
other: (
T_COMPLEX
| Sequence[T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| Index[T_COMPLEX]
),
self: Index[T_COMPLEX], other: np_ndarray_complex | Index[complex]
) -> Index[complex]: ...
@overload
def __add__(
Expand All @@ -560,60 +541,43 @@ class Index(IndexOpsMixin[S1]):
@overload
def __radd__(self: Index[Never], other: complex | _ListLike | Index) -> Index: ...
@overload
def __radd__(
self: Index[bool],
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX],
) -> Index[T_COMPLEX]: ...
def __radd__(self: Index[bool], other: bool | Sequence[bool]) -> Index[bool]: ...
@overload
def __radd__(self: Index[bool], other: np_ndarray_bool) -> Index[bool]: ...
def __radd__(self: Index[int], other: bool | Sequence[bool]) -> Index[int]: ...
@overload
def __radd__(self: Index[bool], other: np_ndarray_anyint) -> Index[int]: ...
def __radd__(self: Index[float], other: int | Sequence[int]) -> Index[float]: ...
@overload
def __radd__(self: Index[bool], other: np_ndarray_float) -> Index[float]: ...
def __radd__(
self: Index[complex], other: float | Sequence[float]
) -> Index[complex]: ...
@overload
def __radd__(
self: Index[int],
other: (
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Index[bool]
),
) -> Index[int]: ...
self: Index[S1_CT],
other: SupportsAdd[S1_CT, S1_CO] | Sequence[SupportsAdd[S1_CT, S1_CO]],
) -> Index[S1_CO]: ...
@overload
def __radd__(
self: Index[int], other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX]
self: Index[T_COMPLEX], other: np_ndarray_bool | Index[bool]
) -> Index[T_COMPLEX]: ...
@overload
def __radd__(self: Index[int], other: np_ndarray_float) -> Index[float]: ...
@overload
def __radd__(
self: Index[float],
other: (
int
| Sequence[int]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[T_INT]
),
) -> Index[float]: ...
self: Index[bool], other: np_ndarray_anyint | Index[int]
) -> Index[int]: ...
@overload
def __radd__(
self: Index[float], other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX]
self: Index[T_COMPLEX], other: np_ndarray_anyint | Index[int]
) -> Index[T_COMPLEX]: ...
@overload
def __radd__(
self: Index[complex],
other: (
T_COMPLEX
| Sequence[T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[T_COMPLEX]
),
) -> Index[complex]: ...
self: Index[bool] | Index[int], other: np_ndarray_float | Index[float]
) -> Index[float]: ...
@overload
def __radd__(
self: Index[T_COMPLEX], other: np_ndarray_float | Index[float]
) -> Index[T_COMPLEX]: ...
@overload
def __radd__(
self: Index[T_COMPLEX], other: np_ndarray_complex
self: Index[T_COMPLEX], other: np_ndarray_complex | Index[complex]
) -> Index[complex]: ...
@overload
def __radd__(
Expand Down
7 changes: 5 additions & 2 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ class DatetimeIndex(

# various ignores needed for mypy, as we do want to restrict what can be used in
# arithmetic for these types
def __add__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset # type: ignore[override]
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | TimedeltaIndex | BaseOffset
) -> DatetimeIndex: ...
def __radd__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | TimedeltaIndex | BaseOffset
) -> DatetimeIndex: ...
@overload # type: ignore[override]
def __sub__(
Expand Down
6 changes: 6 additions & 0 deletions pandas-stubs/core/indexes/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
) -> Self: ...
@property
def values(self) -> np_1darray[np.object_]: ...
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: datetime.timedelta
) -> Self: ...
def __radd__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: datetime.timedelta
) -> Self: ...
@overload # type: ignore[override]
def __sub__(self, other: Period) -> Index: ...
@overload
Expand Down
18 changes: 11 additions & 7 deletions pandas-stubs/core/indexes/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ from pandas.core.indexes.period import PeriodIndex
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs import (
Timedelta,
Timestamp,
)
from pandas._libs import Timedelta
from pandas._libs.tslibs import BaseOffset
from pandas._typing import (
AxesData,
Expand Down Expand Up @@ -53,12 +50,19 @@ class TimedeltaIndex(
@overload # type: ignore[override]
def __add__(self, other: Period) -> PeriodIndex: ...
@overload
def __add__(self, other: DatetimeIndex) -> DatetimeIndex: ...
def __add__(self, other: dt.datetime | DatetimeIndex) -> DatetimeIndex: ...
@overload
def __add__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: dt.timedelta | Timedelta | Self
self, other: dt.timedelta | Self
) -> Self: ...
@overload # type: ignore[override]
def __radd__(self, other: Period) -> PeriodIndex: ...
@overload
def __radd__(self, other: dt.datetime | DatetimeIndex) -> DatetimeIndex: ...
@overload
def __radd__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: dt.timedelta | Self
) -> Self: ...
def __radd__(self, other: dt.datetime | Timestamp | DatetimeIndex) -> DatetimeIndex: ... # type: ignore[override]
def __sub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: dt.timedelta | np.timedelta64 | np_ndarray_td | Self
) -> Self: ...
Expand Down
Loading
Loading