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/core/arraylike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class OpsMixin:
def __rxor__(self, other: Any) -> Self: ...
# -------------------------------------------------------------
# Arithmetic Methods
def __sub__(self, other: Any) -> Self: ...
def __rsub__(self, other: Any) -> Self: ...
def __mul__(self, other: Any) -> Self: ...
def __rmul__(self, other: Any) -> Self: ...
# Handled by subclasses that specify only the valid values
Expand Down
16 changes: 16 additions & 0 deletions pandas-stubs/core/base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import (
Hashable,
Iterator,
Sequence,
)
from typing import (
Any,
Expand Down Expand Up @@ -34,6 +35,10 @@ from pandas._typing import (
SequenceNotStr,
SupportsDType,
np_1darray,
np_ndarray_anyint,
np_ndarray_bool,
np_ndarray_complex,
np_ndarray_float,
)
from pandas.util._decorators import cache_readonly

Expand Down Expand Up @@ -160,3 +165,14 @@ class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]):
sorter: _ListLike | None = ...,
) -> np.intp: ...
def drop_duplicates(self, *, keep: DropKeep = ...) -> Self: ...

NumListLike: TypeAlias = (
ExtensionArray
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| np_ndarray_complex
| dict[str, np.ndarray]
| Sequence[complex]
| IndexOpsMixin[complex]
)
37 changes: 16 additions & 21 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,22 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
level: Level | None = None,
fill_value: float | None = None,
) -> Self: ...
def __sub__(self, other: Any) -> Self: ...
def sub(
self,
other: num | ListLike | DataFrame,
axis: Axis | None = ...,
level: Level | None = ...,
fill_value: float | None = None,
) -> Self: ...
def __rsub__(self, other: Any) -> Self: ...
def rsub(
self,
other,
axis: Axis = ...,
level: Level | None = ...,
fill_value: float | None = None,
) -> Self: ...
@final
def add_prefix(self, prefix: _str, axis: Axis | None = None) -> Self: ...
@final
Expand Down Expand Up @@ -2353,13 +2369,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
level: Level | None = ...,
fill_value: float | None = None,
) -> Self: ...
def rsub(
self,
other,
axis: Axis = ...,
level: Level | None = ...,
fill_value: float | None = None,
) -> Self: ...
def rtruediv(
self,
other,
Expand Down Expand Up @@ -2405,20 +2414,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
numeric_only: _bool = False,
**kwargs: Any,
) -> Series: ...
def sub(
self,
other: num | ListLike | DataFrame,
axis: Axis | None = ...,
level: Level | None = ...,
fill_value: float | None = None,
) -> Self: ...
def subtract(
self,
other: num | ListLike | DataFrame,
axis: Axis | None = ...,
level: Level | None = ...,
fill_value: float | None = None,
) -> Self: ...
def sum(
self,
axis: Axis = 0,
Expand Down
148 changes: 144 additions & 4 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ from pandas import (
TimedeltaIndex,
)
from pandas.core.arrays import ExtensionArray
from pandas.core.base import IndexOpsMixin
from pandas.core.base import (
IndexOpsMixin,
NumListLike,
_ListLike,
)
from pandas.core.strings.accessor import StringMethods
from typing_extensions import (
Never,
Self,
TypeAlias,
)

from pandas._libs.interval import _OrderableT
Expand All @@ -60,6 +63,7 @@ from pandas._typing import (
GenericT_co,
HashableT,
IgnoreRaise,
Just,
Label,
Level,
MaskType,
Expand All @@ -82,8 +86,6 @@ from pandas._typing import (

class InvalidIndexError(Exception): ...

_ListLike: TypeAlias = ArrayLike | dict[_str, np.ndarray] | SequenceNotStr[S1]

class Index(IndexOpsMixin[S1]):
__hash__: ClassVar[None] # type: ignore[assignment]
# overloads with additional dtypes
Expand Down Expand Up @@ -626,6 +628,144 @@ class Index(IndexOpsMixin[S1]):
self: Index[_str], other: _str | Sequence[_str] | np_ndarray_str | Index[_str]
) -> Index[_str]: ...
@overload
def __sub__(self: Index[Never], other: DatetimeIndex) -> Never: ...
@overload
def __sub__(self: Index[Never], other: complex | NumListLike | Index) -> Index: ...
@overload
def __sub__(self, other: Index[Never]) -> Index: ...
@overload
def __sub__(
self: Index[bool],
other: Just[int] | Sequence[Just[int]] | np_ndarray_anyint | Index[int],
) -> Index[int]: ...
@overload
def __sub__(
self: Index[bool],
other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float],
) -> Index[float]: ...
@overload
def __sub__(
self: Index[int],
other: (
int
| Sequence[int]
| np_ndarray_bool
| np_ndarray_anyint
| Index[bool]
| Index[int]
),
) -> Index[int]: ...
@overload
def __sub__(
self: Index[int],
other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float],
) -> Index[float]: ...
@overload
def __sub__(
self: Index[float],
other: (
float
| Sequence[float]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[bool]
| Index[int]
| Index[float]
),
) -> Index[float]: ...
@overload
def __sub__(
self: Index[complex],
other: (
T_COMPLEX
| Sequence[T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[T_COMPLEX]
),
) -> Index[complex]: ...
@overload
def __sub__(
self: Index[T_COMPLEX],
other: (
Just[complex]
| Sequence[Just[complex]]
| np_ndarray_complex
| Index[complex]
),
) -> Index[complex]: ...
@overload
def __rsub__(self: Index[Never], other: DatetimeIndex) -> Never: ... # type: ignore[misc]
@overload
def __rsub__(self: Index[Never], other: complex | NumListLike | Index) -> Index: ...
@overload
def __rsub__(self, other: Index[Never]) -> Index: ...
@overload
def __rsub__(
self: Index[bool],
other: Just[int] | Sequence[Just[int]] | np_ndarray_anyint | Index[int],
) -> Index[int]: ...
@overload
def __rsub__(
self: Index[bool],
other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float],
) -> Index[float]: ...
@overload
def __rsub__(
self: Index[int],
other: (
int
| Sequence[int]
| np_ndarray_bool
| np_ndarray_anyint
| Index[bool]
| Index[int]
),
) -> Index[int]: ...
@overload
def __rsub__(
self: Index[int],
other: Just[float] | Sequence[Just[float]] | np_ndarray_float | Index[float],
) -> Index[float]: ...
@overload
def __rsub__(
self: Index[float],
other: (
float
| Sequence[float]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[bool]
| Index[int]
| Index[float]
),
) -> Index[float]: ...
@overload
def __rsub__(
self: Index[complex],
other: (
T_COMPLEX
| Sequence[T_COMPLEX]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[T_COMPLEX]
),
) -> Index[complex]: ...
@overload
def __rsub__(
self: Index[T_COMPLEX],
other: (
Just[complex]
| Sequence[Just[complex]]
| np_ndarray_complex
| Index[complex]
),
) -> Index[complex]: ...
@overload
def __mul__(
self: Index[int] | Index[float], other: timedelta
) -> TimedeltaIndex: ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/datetimelike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1, GenericT_co]):
def argmax(
self, axis: AxisIndex | None = None, skipna: bool = True, *args, **kwargs
) -> np.int64: ...
def __rsub__( # type: ignore[override]
def __rsub__( # type: ignore[misc,override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: DatetimeIndexOpsMixin
) -> TimedeltaIndex: ...

Expand Down
11 changes: 7 additions & 4 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ from pandas._typing import (
IntervalClosedType,
TimeUnit,
TimeZones,
np_ndarray_dt,
np_ndarray_td,
)

from pandas.core.dtypes.dtypes import DatetimeTZDtype
Expand Down Expand Up @@ -67,15 +69,16 @@ class DatetimeIndex(
def __add__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset
) -> DatetimeIndex: ...
@overload
@overload # type: ignore[override]
def __sub__(self, other: TimedeltaSeries) -> TimestampSeries: ...
@overload
def __sub__(
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset
self,
other: timedelta | np.timedelta64 | np_ndarray_td | TimedeltaIndex | BaseOffset,
) -> DatetimeIndex: ...
@overload
def __sub__(
self, other: datetime | Timestamp | DatetimeIndex
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: datetime | np.datetime64 | np_ndarray_dt | DatetimeIndex
) -> TimedeltaIndex: ...
@final
def to_series(self, index=..., name: Hashable = ...) -> TimestampSeries: ...
Expand Down
6 changes: 4 additions & 2 deletions pandas-stubs/core/indexes/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
) -> Self: ...
@property
def values(self) -> np_1darray[np.object_]: ...
@overload
@overload # type: ignore[override]
def __sub__(self, other: Period) -> Index: ...
@overload
def __sub__(self, other: Self) -> Index: ...
Expand All @@ -45,7 +45,9 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
def __sub__(self, other: TimedeltaIndex | pd.Timedelta) -> Self: ...
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: TimedeltaIndex | pd.Timedelta
) -> Self: ...
@overload # type: ignore[override]
def __rsub__(self, other: Period) -> Index: ...
@overload
Expand Down
5 changes: 4 additions & 1 deletion pandas-stubs/core/indexes/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ from pandas._libs.tslibs import BaseOffset
from pandas._typing import (
AxesData,
TimedeltaConvertibleTypes,
np_ndarray_td,
num,
)

Expand Down Expand Up @@ -58,7 +59,9 @@ class TimedeltaIndex(
self, other: dt.timedelta | Timedelta | Self
) -> Self: ...
def __radd__(self, other: dt.datetime | Timestamp | DatetimeIndex) -> DatetimeIndex: ... # type: ignore[override]
def __sub__(self, other: dt.timedelta | Timedelta | Self) -> Self: ...
def __sub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: dt.timedelta | np.timedelta64 | np_ndarray_td | Self
) -> Self: ...
def __mul__(self, other: num) -> Self: ...
@overload # type: ignore[override]
def __truediv__(self, other: num | Sequence[float]) -> Self: ...
Expand Down
Loading
Loading