Skip to content
Closed
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
36 changes: 34 additions & 2 deletions pandas-stubs/core/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class ElementOpsMixin(Generic[S2]):
) -> ElementOpsMixin[complex]: ...
@overload
def _proto_truediv(
self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
) -> ElementOpsMixin[float]: ...
@overload
def _proto_rtruediv(
Expand All @@ -296,8 +296,32 @@ class ElementOpsMixin(Generic[S2]):
) -> ElementOpsMixin[complex]: ...
@overload
def _proto_rtruediv(
self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
) -> ElementOpsMixin[float]: ...
@overload
def _proto_floordiv(
self: ElementOpsMixin[int], other: int | np.integer
) -> ElementOpsMixin[int]: ...
@overload
def _proto_floordiv(
self: ElementOpsMixin[float], other: float | np.floating
) -> ElementOpsMixin[float]: ...
@overload
def _proto_floordiv(
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
) -> ElementOpsMixin[int]: ...
@overload
def _proto_rfloordiv(
self: ElementOpsMixin[int], other: int | np.integer
) -> ElementOpsMixin[int]: ...
@overload
def _proto_rfloordiv(
self: ElementOpsMixin[float], other: float | np.floating
) -> ElementOpsMixin[float]: ...
@overload
def _proto_rfloordiv(
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
) -> ElementOpsMixin[int]: ...

@type_check_only
class Supports_ProtoAdd(Protocol[_T_contra, S2]):
Expand All @@ -322,3 +346,11 @@ class Supports_ProtoTrueDiv(Protocol[_T_contra, S2]):
@type_check_only
class Supports_ProtoRTrueDiv(Protocol[_T_contra, S2]):
def _proto_rtruediv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...

@type_check_only
class Supports_ProtoFloorDiv(Protocol[_T_contra, S2]):
def _proto_floordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...

@type_check_only
class Supports_ProtoRFloorDiv(Protocol[_T_contra, S2]):
def _proto_rfloordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
157 changes: 137 additions & 20 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,37 @@ from _typeshed import (
_T_contra,
)
import numpy as np
from pandas import (
DataFrame,
DatetimeIndex,
Interval,
IntervalIndex,
MultiIndex,
Period,
PeriodDtype,
PeriodIndex,
Series,
TimedeltaIndex,
)
from pandas.core.base import (
ElementOpsMixin,
IndexOpsMixin,
Supports_ProtoAdd,
Supports_ProtoFloorDiv,
Supports_ProtoMul,
Supports_ProtoRAdd,
Supports_ProtoRFloorDiv,
Supports_ProtoRMul,
Supports_ProtoRTrueDiv,
Supports_ProtoTrueDiv,
)
from pandas.core.frame import DataFrame
from pandas.core.indexes.category import CategoricalIndex
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.interval import IntervalIndex
from pandas.core.indexes.multi import MultiIndex
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from pandas.core.strings.accessor import StringMethods
from typing_extensions import (
Never,
Self,
)

from pandas._libs.interval import _OrderableT
from pandas._libs.interval import (
Interval,
_OrderableT,
)
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._typing import (
C2,
Expand Down Expand Up @@ -92,6 +93,7 @@ from pandas._typing import (
TimedeltaDtypeArg,
TimestampDtypeArg,
np_1darray,
np_ndarray,
np_ndarray_anyint,
np_ndarray_bool,
np_ndarray_complex,
Expand All @@ -102,6 +104,8 @@ from pandas._typing import (
type_t,
)

from pandas.core.dtypes.dtypes import PeriodDtype

class InvalidIndexError(Exception): ...

class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
Expand Down Expand Up @@ -894,14 +898,17 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
@overload
def __truediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ...
@overload
def __truediv__(self, other: np_ndarray_dt) -> Never: ...
@overload
def __truediv__(self: Index[T_COMPLEX], other: np_ndarray_td) -> Never: ...
@overload
def __truediv__(
self: Supports_ProtoTrueDiv[_T_contra, S2],
other: _T_contra | Sequence[_T_contra],
) -> Index[S2]: ...
@overload
def __truediv__(
self: Index[int],
other: np_ndarray_bool | Index[bool],
self: Index[int], other: np_ndarray_bool | Index[bool]
) -> Index[float]: ...
@overload
def __truediv__(
Expand Down Expand Up @@ -945,10 +952,12 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index
) -> Index: ...
@overload
def __rtruediv__(self, other: Index[Never]) -> Index: ...
def __rtruediv__(self, other: Index[Never]) -> Index: ... # type: ignore[overload-overlap]
@overload
def __rtruediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ...
@overload
def __rtruediv__(self, other: np_ndarray_dt) -> Never: ...
@overload
def __rtruediv__(
self: Supports_ProtoRTrueDiv[_T_contra, S2],
other: _T_contra | Sequence[_T_contra],
Expand Down Expand Up @@ -993,13 +1002,121 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
),
) -> Index[complex]: ...
@overload
def __rtruediv__(
self: Index[int] | Index[float],
other: timedelta | np.timedelta64 | np_ndarray_td | TimedeltaIndex,
) -> TimedeltaIndex: ...
@overload
def __rtruediv__(self, other: Path) -> Index: ...
@overload
def __floordiv__(
self, other: float | Sequence[float] | Index[int] | Index[float]
) -> Self: ...
self: Index[Never],
other: (
float
| Sequence[float]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[bool]
| Index[int]
| Index[float]
),
) -> Index: ...
@overload
def __floordiv__(
self: Index[bool] | Index[int] | Index[float], other: Index[Never]
) -> Index: ...
@overload
def __floordiv__(
self: Index[int] | Index[float],
other: np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
) -> Never: ...
@overload
def __floordiv__(
self: Index[bool] | Index[complex], other: np_ndarray
) -> Never: ...
@overload
def __floordiv__(
self: Supports_ProtoFloorDiv[_T_contra, S2],
other: _T_contra | Sequence[_T_contra],
) -> Index[S2]: ...
@overload
def __floordiv__(
self: Index[int], other: np_ndarray_bool | Index[bool]
) -> Index[int]: ...
@overload
def __floordiv__(
self: Index[float], other: np_ndarray_bool | Index[bool]
) -> Index[float]: ...
@overload
def __floordiv__(
self: Index[bool] | Index[int], other: np_ndarray_anyint | Index[int]
) -> Index[int]: ...
@overload
def __floordiv__(
self: Index[float], other: np_ndarray_anyint | Index[int]
) -> Index[float]: ...
@overload
def __floordiv__(
self: Index[int] | Index[float],
other: float | Sequence[float] | np_ndarray_float | Index[float],
) -> Index[float]: ...
@overload
def __rfloordiv__(
self, other: float | Sequence[float] | Index[int] | Index[float]
) -> Self: ...
self: Index[Never],
other: (
float
| Sequence[float]
| np_ndarray_bool
| np_ndarray_anyint
| np_ndarray_float
| Index[bool]
| Index[int]
| Index[float]
),
) -> Index: ...
@overload
def __rfloordiv__(self: Index[bool] | Index[int] | Index[float], other: Index[Never]) -> Index: ... # type: ignore[overload-overlap]
@overload
def __rfloordiv__(
self: Index[int] | Index[float],
other: np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
) -> Never: ...
@overload
def __rfloordiv__(
self: Index[bool] | Index[complex], other: np_ndarray
) -> Never: ...
@overload
def __rfloordiv__(
self: Supports_ProtoRFloorDiv[_T_contra, S2],
other: _T_contra | Sequence[_T_contra],
) -> Index[S2]: ...
@overload
def __rfloordiv__(
self: Index[int], other: np_ndarray_bool | Index[bool]
) -> Index[int]: ...
@overload
def __rfloordiv__(
self: Index[float], other: np_ndarray_bool | Index[bool]
) -> Index[float]: ...
@overload
def __rfloordiv__(
self: Index[bool] | Index[int], other: np_ndarray_anyint | Index[int]
) -> Index[int]: ...
@overload
def __rfloordiv__(
self: Index[float], other: np_ndarray_anyint | Index[int]
) -> Index[float]: ...
@overload
def __rfloordiv__(
self: Index[int] | Index[float],
other: float | Sequence[float] | np_ndarray_float | Index[float],
) -> Index[float]: ...
@overload
def __rfloordiv__(
self: Index[int] | Index[float],
other: timedelta | np_ndarray_td | TimedeltaIndex,
) -> TimedeltaIndex: ...
def infer_objects(self, copy: bool = True) -> Self: ...

@type_check_only
Expand Down
27 changes: 17 additions & 10 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ from typing import (
)

import numpy as np
from pandas import (
DataFrame,
Index,
TimedeltaIndex,
Timestamp,
)
from pandas.core.frame import DataFrame
from pandas.core.indexes.accessors import DatetimeIndexProperties
from pandas.core.indexes.base import Index
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import Self
from typing_extensions import (
Never,
Self,
)

from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
AxesData,
DateAndDatetimeLike,
Expand All @@ -34,6 +35,7 @@ from pandas._typing import (
TimeUnit,
TimeZones,
np_1darray,
np_ndarray,
np_ndarray_dt,
np_ndarray_td,
)
Expand Down Expand Up @@ -63,18 +65,23 @@ class DatetimeIndex(
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | BaseOffset
) -> Self: ...
def __radd__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __radd__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | BaseOffset
) -> Self: ...
@overload # type: ignore[override]
# pyrefly: ignore # bad-override
def __sub__(
def __sub__( # pyrefly: ignore[bad-override]
self, other: datetime | np.datetime64 | np_ndarray_dt | Self
) -> TimedeltaIndex: ...
@overload
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: timedelta | np.timedelta64 | np_ndarray_td | BaseOffset
) -> Self: ...
def __truediv__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore[bad-override]
self, other: np_ndarray
) -> Never: ...
def __rtruediv__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore[bad-override]
self, other: np_ndarray
) -> Never: ...
@final
def to_series(
self, index: Index | None = None, name: Hashable | None = None
Expand Down
Loading