Skip to content

Commit d5f210f

Browse files
committed
floordiv
1 parent 6957ad1 commit d5f210f

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
@@ -28,36 +28,37 @@ from _typeshed import (
2828
_T_contra,
2929
)
3030
import numpy as np
31-
from pandas import (
32-
DataFrame,
33-
DatetimeIndex,
34-
Interval,
35-
IntervalIndex,
36-
MultiIndex,
37-
Period,
38-
PeriodDtype,
39-
PeriodIndex,
40-
Series,
41-
TimedeltaIndex,
42-
)
4331
from pandas.core.base import (
4432
ElementOpsMixin,
4533
IndexOpsMixin,
4634
Supports_ProtoAdd,
35+
Supports_ProtoFloorDiv,
4736
Supports_ProtoMul,
4837
Supports_ProtoRAdd,
38+
Supports_ProtoRFloorDiv,
4939
Supports_ProtoRMul,
5040
Supports_ProtoRTrueDiv,
5141
Supports_ProtoTrueDiv,
5242
)
43+
from pandas.core.frame import DataFrame
5344
from pandas.core.indexes.category import CategoricalIndex
45+
from pandas.core.indexes.datetimes import DatetimeIndex
46+
from pandas.core.indexes.interval import IntervalIndex
47+
from pandas.core.indexes.multi import MultiIndex
48+
from pandas.core.indexes.period import PeriodIndex
49+
from pandas.core.indexes.timedeltas import TimedeltaIndex
50+
from pandas.core.series import Series
5451
from pandas.core.strings.accessor import StringMethods
5552
from typing_extensions import (
5653
Never,
5754
Self,
5855
)
5956

60-
from pandas._libs.interval import _OrderableT
57+
from pandas._libs.interval import (
58+
Interval,
59+
_OrderableT,
60+
)
61+
from pandas._libs.tslibs.period import Period
6162
from pandas._libs.tslibs.timedeltas import Timedelta
6263
from pandas._typing import (
6364
C2,
@@ -94,6 +95,7 @@ from pandas._typing import (
9495
TimedeltaDtypeArg,
9596
TimestampDtypeArg,
9697
np_1darray,
98+
np_ndarray,
9799
np_ndarray_anyint,
98100
np_ndarray_bool,
99101
np_ndarray_complex,
@@ -104,6 +106,8 @@ from pandas._typing import (
104106
type_t,
105107
)
106108

109+
from pandas.core.dtypes.dtypes import PeriodDtype
110+
107111
class InvalidIndexError(Exception): ...
108112

109113
class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
@@ -911,14 +915,17 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
911915
@overload
912916
def __truediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ...
913917
@overload
918+
def __truediv__(self, other: np_ndarray_dt) -> Never: ...
919+
@overload
920+
def __truediv__(self: Index[T_COMPLEX], other: np_ndarray_td) -> Never: ...
921+
@overload
914922
def __truediv__(
915923
self: Supports_ProtoTrueDiv[_T_contra, S2],
916924
other: _T_contra | Sequence[_T_contra],
917925
) -> Index[S2]: ...
918926
@overload
919927
def __truediv__(
920-
self: Index[int],
921-
other: np_ndarray_bool | Index[bool],
928+
self: Index[int], other: np_ndarray_bool | Index[bool]
922929
) -> Index[float]: ...
923930
@overload
924931
def __truediv__(
@@ -962,10 +969,12 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
962969
self: Index[Never], other: complex | ArrayLike | SequenceNotStr[S1] | Index
963970
) -> Index: ...
964971
@overload
965-
def __rtruediv__(self, other: Index[Never]) -> Index: ...
972+
def __rtruediv__(self, other: Index[Never]) -> Index: ... # type: ignore[overload-overlap]
966973
@overload
967974
def __rtruediv__(self: Index[bool], other: np_ndarray_bool) -> Never: ...
968975
@overload
976+
def __rtruediv__(self, other: np_ndarray_dt) -> Never: ...
977+
@overload
969978
def __rtruediv__(
970979
self: Supports_ProtoRTrueDiv[_T_contra, S2],
971980
other: _T_contra | Sequence[_T_contra],
@@ -1010,13 +1019,91 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
10101019
),
10111020
) -> Index[complex]: ...
10121021
@overload
1022+
def __rtruediv__(
1023+
self: Index[int] | Index[float],
1024+
other: timedelta | np.timedelta64 | np_ndarray_td | TimedeltaIndex,
1025+
) -> TimedeltaIndex: ...
1026+
@overload
10131027
def __rtruediv__(self, other: Path) -> Index: ...
1028+
@overload
1029+
def __floordiv__(self, other: Index[Never]) -> Index: ...
1030+
@overload
10141031
def __floordiv__(
1015-
self, other: float | Sequence[float] | Index[int] | Index[float]
1016-
) -> Self: ...
1032+
self: Index[int] | Index[float],
1033+
other: np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
1034+
) -> Never: ...
1035+
@overload
1036+
def __floordiv__(
1037+
self: Index[bool] | Index[complex], other: np_ndarray
1038+
) -> Never: ...
1039+
@overload
1040+
def __floordiv__(
1041+
self: Supports_ProtoFloorDiv[_T_contra, S2],
1042+
other: _T_contra | Sequence[_T_contra],
1043+
) -> Index[S2]: ...
1044+
@overload
1045+
def __floordiv__(
1046+
self: Index[int], other: np_ndarray_bool | Index[bool]
1047+
) -> Index[int]: ...
1048+
@overload
1049+
def __floordiv__(
1050+
self: Index[float], other: np_ndarray_bool | Index[bool]
1051+
) -> Index[float]: ...
1052+
@overload
1053+
def __floordiv__(
1054+
self: Index[bool] | Index[int], other: np_ndarray_anyint | Index[int]
1055+
) -> Index[int]: ...
1056+
@overload
1057+
def __floordiv__(
1058+
self: Index[float], other: np_ndarray_anyint | Index[int]
1059+
) -> Index[float]: ...
1060+
@overload
1061+
def __floordiv__(
1062+
self: Index[int] | Index[float],
1063+
other: float | Sequence[float] | np_ndarray_float | Index[float],
1064+
) -> Index[float]: ...
1065+
@overload
1066+
def __rfloordiv__(self, other: Index[Never]) -> Index: ... # type: ignore[overload-overlap]
1067+
@overload
10171068
def __rfloordiv__(
1018-
self, other: float | Sequence[float] | Index[int] | Index[float]
1019-
) -> Self: ...
1069+
self: Index[int] | Index[float],
1070+
other: np_ndarray_complex | np_ndarray_dt | np_ndarray_td,
1071+
) -> Never: ...
1072+
@overload
1073+
def __rfloordiv__(
1074+
self: Index[bool] | Index[complex], other: np_ndarray
1075+
) -> Never: ...
1076+
@overload
1077+
def __rfloordiv__(
1078+
self: Supports_ProtoRFloorDiv[_T_contra, S2],
1079+
other: _T_contra | Sequence[_T_contra],
1080+
) -> Index[S2]: ...
1081+
@overload
1082+
def __rfloordiv__(
1083+
self: Index[int], other: np_ndarray_bool | Index[bool]
1084+
) -> Index[int]: ...
1085+
@overload
1086+
def __rfloordiv__(
1087+
self: Index[float], other: np_ndarray_bool | Index[bool]
1088+
) -> Index[float]: ...
1089+
@overload
1090+
def __rfloordiv__(
1091+
self: Index[bool] | Index[int], other: np_ndarray_anyint | Index[int]
1092+
) -> Index[int]: ...
1093+
@overload
1094+
def __rfloordiv__(
1095+
self: Index[float], other: np_ndarray_anyint | Index[int]
1096+
) -> Index[float]: ...
1097+
@overload
1098+
def __rfloordiv__(
1099+
self: Index[int] | Index[float],
1100+
other: float | Sequence[float] | np_ndarray_float | Index[float],
1101+
) -> Index[float]: ...
1102+
@overload
1103+
def __rfloordiv__(
1104+
self: Index[int] | Index[float],
1105+
other: timedelta | np_ndarray_td | TimedeltaIndex,
1106+
) -> TimedeltaIndex: ...
10201107
def infer_objects(self, copy: bool = True) -> Self: ...
10211108

10221109
@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)