Skip to content

Commit 0483ca4

Browse files
committed
floordiv
1 parent 251b9ad commit 0483ca4

File tree

15 files changed

+1180
-342
lines changed

15 files changed

+1180
-342
lines changed

pandas-stubs/core/base.pyi

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ from pandas._libs.tslibs.timedeltas import Timedelta
2929
from pandas._typing import (
3030
S1,
3131
S2,
32+
S3,
3233
AxisIndex,
3334
DropKeep,
3435
DTypeLike,
@@ -280,7 +281,7 @@ class ElementOpsMixin(Generic[S2]):
280281
) -> ElementOpsMixin[complex]: ...
281282
@overload
282283
def _proto_truediv(
283-
self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64
284+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
284285
) -> ElementOpsMixin[float]: ...
285286
@overload
286287
def _proto_rtruediv(
@@ -296,8 +297,56 @@ class ElementOpsMixin(Generic[S2]):
296297
) -> ElementOpsMixin[complex]: ...
297298
@overload
298299
def _proto_rtruediv(
299-
self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64
300+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
300301
) -> ElementOpsMixin[float]: ...
302+
@overload
303+
def _proto_floordiv(
304+
self: ElementOpsMixin[int], other: int | np.integer
305+
) -> ElementOpsMixin[int]: ...
306+
@overload
307+
def _proto_floordiv(
308+
self: ElementOpsMixin[float], other: float | np.floating
309+
) -> ElementOpsMixin[float]: ...
310+
@overload
311+
def _proto_floordiv(
312+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
313+
) -> ElementOpsMixin[int]: ...
314+
@overload
315+
def _proto_rfloordiv(
316+
self: ElementOpsMixin[int], other: int | np.integer
317+
) -> ElementOpsMixin[int]: ...
318+
@overload
319+
def _proto_rfloordiv(
320+
self: ElementOpsMixin[float], other: float | np.floating
321+
) -> ElementOpsMixin[float]: ...
322+
@overload
323+
def _proto_rfloordiv(
324+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
325+
) -> ElementOpsMixin[int]: ...
326+
@overload
327+
def _proto_mod(
328+
self: ElementOpsMixin[int], other: int | np.integer
329+
) -> ElementOpsMixin[int]: ...
330+
@overload
331+
def _proto_mod(
332+
self: ElementOpsMixin[float], other: float | np.floating
333+
) -> ElementOpsMixin[float]: ...
334+
@overload
335+
def _proto_mod(
336+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
337+
) -> ElementOpsMixin[Timedelta]: ...
338+
@overload
339+
def _proto_rmod(
340+
self: ElementOpsMixin[int], other: int | np.integer
341+
) -> ElementOpsMixin[int]: ...
342+
@overload
343+
def _proto_rmod(
344+
self: ElementOpsMixin[float], other: float | np.floating
345+
) -> ElementOpsMixin[float]: ...
346+
@overload
347+
def _proto_rmod(
348+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
349+
) -> ElementOpsMixin[Timedelta]: ...
301350

302351
@type_check_only
303352
class Supports_ProtoAdd(Protocol[_T_contra, S2]):
@@ -322,3 +371,29 @@ class Supports_ProtoTrueDiv(Protocol[_T_contra, S2]):
322371
@type_check_only
323372
class Supports_ProtoRTrueDiv(Protocol[_T_contra, S2]):
324373
def _proto_rtruediv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
374+
375+
@type_check_only
376+
class Supports_ProtoFloorDiv(Protocol[_T_contra, S2]):
377+
def _proto_floordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
378+
379+
@type_check_only
380+
class Supports_ProtoRFloorDiv(Protocol[_T_contra, S2]):
381+
def _proto_rfloordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
382+
383+
@type_check_only
384+
class Supports_ProtoMod(Protocol[_T_contra, S2]):
385+
def _proto_mod(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
386+
387+
@type_check_only
388+
class Supports_ProtoRMod(Protocol[_T_contra, S2]):
389+
def _proto_rmod(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
390+
391+
@type_check_only
392+
class Supports_ProtoDivMod(Protocol[_T_contra, S2, S3]):
393+
def _proto_floordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
394+
def _proto_mod(self, other: _T_contra, /) -> ElementOpsMixin[S3]: ...
395+
396+
@type_check_only
397+
class Supports_ProtoRDivMod(Protocol[_T_contra, S2, S3]):
398+
def _proto_rfloordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
399+
def _proto_rmod(self, other: _T_contra, /) -> ElementOpsMixin[S3]: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 107 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,38 @@ from _typeshed import (
2929
_T_contra,
3030
)
3131
import numpy as np
32-
from pandas import (
33-
DataFrame,
34-
DatetimeIndex,
35-
Interval,
36-
IntervalIndex,
37-
MultiIndex,
38-
Period,
39-
PeriodDtype,
40-
PeriodIndex,
41-
Series,
42-
TimedeltaIndex,
43-
)
4432
from pandas.core.arrays.boolean import BooleanArray
4533
from pandas.core.base import (
4634
ElementOpsMixin,
4735
IndexOpsMixin,
4836
Supports_ProtoAdd,
37+
Supports_ProtoFloorDiv,
4938
Supports_ProtoMul,
5039
Supports_ProtoRAdd,
40+
Supports_ProtoRFloorDiv,
5141
Supports_ProtoRMul,
5242
Supports_ProtoRTrueDiv,
5343
Supports_ProtoTrueDiv,
5444
)
45+
from pandas.core.frame import DataFrame
5546
from pandas.core.indexes.category import CategoricalIndex
47+
from pandas.core.indexes.datetimes import DatetimeIndex
48+
from pandas.core.indexes.interval import IntervalIndex
49+
from pandas.core.indexes.multi import MultiIndex
50+
from pandas.core.indexes.period import PeriodIndex
51+
from pandas.core.indexes.timedeltas import TimedeltaIndex
52+
from pandas.core.series import Series
5653
from pandas.core.strings.accessor import StringMethods
5754
from typing_extensions import (
5855
Never,
5956
Self,
6057
)
6158

62-
from pandas._libs.interval import _OrderableT
59+
from pandas._libs.interval import (
60+
Interval,
61+
_OrderableT,
62+
)
63+
from pandas._libs.tslibs.period import Period
6364
from pandas._libs.tslibs.timedeltas import Timedelta
6465
from pandas._typing import (
6566
C2,
@@ -97,6 +98,7 @@ from pandas._typing import (
9798
TimedeltaDtypeArg,
9899
TimestampDtypeArg,
99100
np_1darray,
101+
np_ndarray,
100102
np_ndarray_anyint,
101103
np_ndarray_bool,
102104
np_ndarray_complex,
@@ -107,6 +109,8 @@ from pandas._typing import (
107109
type_t,
108110
)
109111

112+
from pandas.core.dtypes.dtypes import PeriodDtype
113+
110114
class InvalidIndexError(Exception): ...
111115

112116
class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
@@ -942,14 +946,17 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
942946
@overload
943947
def __truediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ...
944948
@overload
949+
def __truediv__(self, other: np_ndarray_dt) -> Never: ...
950+
@overload
951+
def __truediv__(self: Index[T_COMPLEX], other: np_ndarray_td) -> Never: ...
952+
@overload
945953
def __truediv__(
946954
self: Supports_ProtoTrueDiv[_T_contra, S2],
947955
other: _T_contra | Sequence[_T_contra],
948956
) -> Index[S2]: ...
949957
@overload
950958
def __truediv__(
951-
self: Index[int],
952-
other: np_ndarray_bool | Index[bool],
959+
self: Index[int], other: np_ndarray_bool | Index[bool]
953960
) -> Index[float]: ...
954961
@overload
955962
def __truediv__(
@@ -993,10 +1000,12 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
9931000
self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index
9941001
) -> Index: ...
9951002
@overload
996-
def __rtruediv__(self, other: Index[Never]) -> Index: ...
1003+
def __rtruediv__(self, other: Index[Never]) -> Index: ... # type: ignore[overload-overlap]
9971004
@overload
9981005
def __rtruediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ...
9991006
@overload
1007+
def __rtruediv__(self, other: np_ndarray_dt) -> Never: ...
1008+
@overload
10001009
def __rtruediv__(
10011010
self: Supports_ProtoRTrueDiv[_T_contra, S2],
10021011
other: _T_contra | Sequence[_T_contra],
@@ -1041,13 +1050,91 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
10411050
),
10421051
) -> Index[complex]: ...
10431052
@overload
1053+
def __rtruediv__(
1054+
self: Index[int] | Index[float],
1055+
other: timedelta | np.timedelta64 | np_ndarray_td | TimedeltaIndex,
1056+
) -> TimedeltaIndex: ...
1057+
@overload
10441058
def __rtruediv__(self, other: Path) -> Index: ...
1059+
@overload
1060+
def __floordiv__(self, other: Index[Never]) -> Index: ...
1061+
@overload
10451062
def __floordiv__(
1046-
self, other: float | Sequence[float] | Index[int] | Index[float]
1047-
) -> Self: ...
1063+
self: Index[int] | Index[float],
1064+
other: np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
1065+
) -> Never: ...
1066+
@overload
1067+
def __floordiv__(
1068+
self: Index[bool] | Index[complex], other: np_ndarray
1069+
) -> Never: ...
1070+
@overload
1071+
def __floordiv__(
1072+
self: Supports_ProtoFloorDiv[_T_contra, S2],
1073+
other: _T_contra | Sequence[_T_contra],
1074+
) -> Index[S2]: ...
1075+
@overload
1076+
def __floordiv__(
1077+
self: Index[int], other: np_ndarray_bool | Index[bool]
1078+
) -> Index[int]: ...
1079+
@overload
1080+
def __floordiv__(
1081+
self: Index[float], other: np_ndarray_bool | Index[bool]
1082+
) -> Index[float]: ...
1083+
@overload
1084+
def __floordiv__(
1085+
self: Index[bool] | Index[int], other: np_ndarray_anyint | Index[int]
1086+
) -> Index[int]: ...
1087+
@overload
1088+
def __floordiv__(
1089+
self: Index[float], other: np_ndarray_anyint | Index[int]
1090+
) -> Index[float]: ...
1091+
@overload
1092+
def __floordiv__(
1093+
self: Index[int] | Index[float],
1094+
other: float | Sequence[float] | np_ndarray_float | Index[float],
1095+
) -> Index[float]: ...
1096+
@overload
1097+
def __rfloordiv__(self, other: Index[Never]) -> Index: ... # type: ignore[overload-overlap]
1098+
@overload
10481099
def __rfloordiv__(
1049-
self, other: float | Sequence[float] | Index[int] | Index[float]
1050-
) -> Self: ...
1100+
self: Index[int] | Index[float],
1101+
other: np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
1102+
) -> Never: ...
1103+
@overload
1104+
def __rfloordiv__(
1105+
self: Index[bool] | Index[complex], other: np_ndarray
1106+
) -> Never: ...
1107+
@overload
1108+
def __rfloordiv__(
1109+
self: Supports_ProtoRFloorDiv[_T_contra, S2],
1110+
other: _T_contra | Sequence[_T_contra],
1111+
) -> Index[S2]: ...
1112+
@overload
1113+
def __rfloordiv__(
1114+
self: Index[int], other: np_ndarray_bool | Index[bool]
1115+
) -> Index[int]: ...
1116+
@overload
1117+
def __rfloordiv__(
1118+
self: Index[float], other: np_ndarray_bool | Index[bool]
1119+
) -> Index[float]: ...
1120+
@overload
1121+
def __rfloordiv__(
1122+
self: Index[bool] | Index[int], other: np_ndarray_anyint | Index[int]
1123+
) -> Index[int]: ...
1124+
@overload
1125+
def __rfloordiv__(
1126+
self: Index[float], other: np_ndarray_anyint | Index[int]
1127+
) -> Index[float]: ...
1128+
@overload
1129+
def __rfloordiv__(
1130+
self: Index[int] | Index[float],
1131+
other: float | Sequence[float] | np_ndarray_float | Index[float],
1132+
) -> Index[float]: ...
1133+
@overload
1134+
def __rfloordiv__(
1135+
self: Index[int] | Index[float],
1136+
other: timedelta | np_ndarray_td | TimedeltaIndex,
1137+
) -> TimedeltaIndex: ...
10511138
def infer_objects(self, copy: bool = True) -> Self: ...
10521139

10531140
@type_check_only

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ from typing import (
1414
)
1515

1616
import numpy as np
17-
from pandas import (
18-
DataFrame,
19-
Index,
20-
TimedeltaIndex,
21-
Timestamp,
22-
)
17+
from pandas.core.frame import DataFrame
2318
from pandas.core.indexes.accessors import DatetimeIndexProperties
19+
from pandas.core.indexes.base import Index
2420
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
21+
from pandas.core.indexes.timedeltas import TimedeltaIndex
2522
from pandas.core.series import Series
26-
from typing_extensions import Self
23+
from typing_extensions import (
24+
Never,
25+
Self,
26+
)
2727

28+
from pandas._libs.tslibs.timestamps import Timestamp
2829
from pandas._typing import (
2930
AxesData,
3031
DateAndDatetimeLike,
@@ -34,6 +35,7 @@ from pandas._typing import (
3435
TimeUnit,
3536
TimeZones,
3637
np_1darray,
38+
np_ndarray,
3739
np_ndarray_dt,
3840
np_ndarray_td,
3941
)
@@ -63,18 +65,23 @@ class DatetimeIndex(
6365
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
6466
self, other: timedelta | BaseOffset
6567
) -> Self: ...
66-
def __radd__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
68+
def __radd__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
6769
self, other: timedelta | BaseOffset
6870
) -> Self: ...
6971
@overload # type: ignore[override]
70-
# pyrefly: ignore # bad-override
71-
def __sub__(
72+
def __sub__( # pyrefly: ignore[bad-override]
7273
self, other: datetime | np.datetime64 | np_ndarray_dt | Self
7374
) -> TimedeltaIndex: ...
7475
@overload
7576
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
7677
self, other: timedelta | np.timedelta64 | np_ndarray_td | BaseOffset
7778
) -> Self: ...
79+
def __truediv__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore[bad-override]
80+
self, other: np_ndarray
81+
) -> Never: ...
82+
def __rtruediv__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore[bad-override]
83+
self, other: np_ndarray
84+
) -> Never: ...
7885
@final
7986
def to_series(
8087
self, index: Index | None = None, name: Hashable | None = None

0 commit comments

Comments
 (0)