Skip to content

Commit fd3bc04

Browse files
authored
fix slice/Hashable overlap. Update mypy and pyright (#1021)
* fix slice/Hashable overlap. Update mypy and pyright * remove slice and tuple from groupby getitem
1 parent 53c299f commit fd3bc04

20 files changed

+93
-97
lines changed

pandas-stubs/_libs/interval.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
201201
@overload
202202
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
203203
@overload
204-
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
204+
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
205205
@overload
206206
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
207207
@overload
208208
def __eq__(self, other: object) -> Literal[False]: ...
209209
@overload
210210
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
211211
@overload
212-
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
212+
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
213213
@overload
214214
def __ne__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
215215
@overload

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Timedelta(timedelta):
248248
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
249249
# maybe related to https://github.com/python/mypy/issues/10755
250250
@overload
251-
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ... # type: ignore[misc]
251+
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
252252
# Override due to more types supported than dt.timedelta
253253
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
254254
@overload # type: ignore[override]

pandas-stubs/core/algorithms.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ from pandas._typing import (
2424
# with extension types return the same type while standard type return ndarray
2525

2626
@overload
27-
def unique(values: PeriodIndex) -> PeriodIndex: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
27+
def unique( # pyright: ignore[reportOverlappingOverload]
28+
values: PeriodIndex,
29+
) -> PeriodIndex: ...
2830
@overload
2931
def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[overload-overlap]
3032
@overload
31-
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... # type: ignore[overload-overlap]
33+
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ...
3234
@overload
3335
def unique(values: Index) -> np.ndarray: ...
3436
@overload

pandas-stubs/core/arrays/datetimelike.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,7 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
6767
def resolution(self): ...
6868
__pow__ = ...
6969
__rpow__ = ...
70-
__mul__ = ...
7170
__rmul__ = ...
72-
__truediv__ = ...
73-
__rtruediv__ = ...
74-
__floordiv__ = ...
75-
__rfloordiv__ = ...
76-
__mod__ = ...
77-
__rmod__ = ...
78-
__divmod__ = ...
79-
__rdivmod__ = ...
8071
def __add__(self, other): ...
8172
def __radd__(self, other): ...
8273
def __sub__(self, other): ...

pandas-stubs/core/frame.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class _LocIndexerFrame(_LocIndexer):
190190
),
191191
) -> DataFrame: ...
192192
@overload
193-
def __getitem__( # pyright: ignore[reportOverlappingOverload]
193+
def __getitem__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
194194
self,
195195
idx: tuple[
196196
int | StrLike | tuple[Scalar, ...] | Callable[[DataFrame], ScalarT],
@@ -307,7 +307,7 @@ class DataFrame(NDFrame, OpsMixin):
307307
na_value: Scalar = ...,
308308
) -> np.ndarray: ...
309309
@overload
310-
def to_dict( # type: ignore[overload-overlap]
310+
def to_dict(
311311
self,
312312
orient: Literal["records"],
313313
*,
@@ -323,31 +323,31 @@ class DataFrame(NDFrame, OpsMixin):
323323
index: Literal[True] = ...,
324324
) -> list[dict[Hashable, Any]]: ...
325325
@overload
326-
def to_dict( # type: ignore[overload-overlap]
326+
def to_dict(
327327
self,
328328
orient: Literal["dict", "list", "series", "index"],
329329
*,
330330
into: MutableMapping | type[MutableMapping],
331331
index: Literal[True] = ...,
332332
) -> MutableMapping[Hashable, Any]: ...
333333
@overload
334-
def to_dict( # type: ignore[overload-overlap]
334+
def to_dict(
335335
self,
336336
orient: Literal["split", "tight"],
337337
*,
338338
into: MutableMapping | type[MutableMapping],
339339
index: bool = ...,
340340
) -> MutableMapping[Hashable, Any]: ...
341341
@overload
342-
def to_dict( # type: ignore[overload-overlap]
342+
def to_dict(
343343
self,
344344
orient: Literal["dict", "list", "series", "index"] = ...,
345345
*,
346346
into: MutableMapping | type[MutableMapping],
347347
index: Literal[True] = ...,
348348
) -> MutableMapping[Hashable, Any]: ...
349349
@overload
350-
def to_dict( # type: ignore[overload-overlap]
350+
def to_dict(
351351
self,
352352
orient: Literal["split", "tight"] = ...,
353353
*,
@@ -1054,7 +1054,7 @@ class DataFrame(NDFrame, OpsMixin):
10541054
errors: IgnoreRaise = ...,
10551055
) -> None: ...
10561056
@overload
1057-
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
1057+
def groupby( # pyright: ignore reportOverlappingOverload
10581058
self,
10591059
by: Scalar,
10601060
axis: AxisIndex | NoDefault = ...,
@@ -1078,7 +1078,7 @@ class DataFrame(NDFrame, OpsMixin):
10781078
dropna: _bool = ...,
10791079
) -> DataFrameGroupBy[Scalar, Literal[False]]: ...
10801080
@overload
1081-
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
1081+
def groupby( # pyright: ignore reportOverlappingOverload
10821082
self,
10831083
by: DatetimeIndex,
10841084
axis: AxisIndex | NoDefault = ...,
@@ -1090,7 +1090,7 @@ class DataFrame(NDFrame, OpsMixin):
10901090
dropna: _bool = ...,
10911091
) -> DataFrameGroupBy[Timestamp, Literal[True]]: ...
10921092
@overload
1093-
def groupby( # type: ignore[overload-overlap]
1093+
def groupby(
10941094
self,
10951095
by: DatetimeIndex,
10961096
axis: AxisIndex | NoDefault = ...,
@@ -1219,7 +1219,7 @@ class DataFrame(NDFrame, OpsMixin):
12191219
) -> DataFrame: ...
12201220
def diff(self, periods: int = ..., axis: Axis = ...) -> DataFrame: ...
12211221
@overload
1222-
def agg( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
1222+
def agg( # pyright: ignore[reportOverlappingOverload]
12231223
self, func: AggFuncTypeBase | AggFuncTypeDictSeries, axis: Axis = ..., **kwargs
12241224
) -> Series: ...
12251225
@overload
@@ -1230,7 +1230,7 @@ class DataFrame(NDFrame, OpsMixin):
12301230
**kwargs,
12311231
) -> DataFrame: ...
12321232
@overload
1233-
def aggregate( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
1233+
def aggregate( # pyright: ignore[reportOverlappingOverload]
12341234
self, func: AggFuncTypeBase | AggFuncTypeDictSeries, axis: Axis = ..., **kwargs
12351235
) -> Series: ...
12361236
@overload

pandas-stubs/core/groupby/generic.pyi

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ _TT = TypeVar("_TT", bound=Literal[True, False])
189189
class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
190190
# error: Overload 3 for "apply" will never be used because its parameters overlap overload 1
191191
@overload # type: ignore[override]
192-
def apply( # type: ignore[overload-overlap]
192+
def apply(
193193
self,
194194
func: Callable[[DataFrame], Scalar | list | dict],
195195
*args,
@@ -234,12 +234,10 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
234234
self, func: Callable, dropna: bool = ..., *args, **kwargs
235235
) -> DataFrame: ...
236236
@overload
237-
def __getitem__( # type: ignore[overload-overlap]
238-
self, key: Scalar | Hashable | tuple[Hashable, ...]
239-
) -> SeriesGroupBy[Any, ByT]: ...
237+
def __getitem__(self, key: Scalar) -> SeriesGroupBy[Any, ByT]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
240238
@overload
241-
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride, reportOverlappingOverload]
242-
self, key: Iterable[Hashable] | slice
239+
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride]
240+
self, key: Iterable[Hashable]
243241
) -> DataFrameGroupBy[ByT, bool]: ...
244242
def nunique(self, dropna: bool = ...) -> DataFrame: ...
245243
def idxmax(
@@ -324,7 +322,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
324322
self, indices: TakeIndexer, axis: Axis | None | NoDefault = ..., **kwargs
325323
) -> DataFrame: ...
326324
@overload
327-
def skew( # type: ignore[overload-overlap]
325+
def skew(
328326
self,
329327
axis: Axis | None | NoDefault = ...,
330328
skipna: bool = ...,

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,15 @@ class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
139139
@final
140140
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ...
141141
@overload
142-
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar | Hashable | tuple[Hashable, ...]) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap]
142+
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
143143
@overload
144-
def __getitem__( # pyright: ignore[reportOverlappingOverload]
145-
self: BaseGroupBy[DataFrame], key: Iterable[Hashable] | slice
144+
def __getitem__(
145+
self: BaseGroupBy[DataFrame], key: Iterable[Hashable]
146146
) -> generic.DataFrameGroupBy: ...
147147
@overload
148148
def __getitem__(
149149
self: BaseGroupBy[Series[S1]],
150-
idx: (
151-
list[str]
152-
| Index
153-
| Series[S1]
154-
| slice
155-
| MaskType
156-
| tuple[Hashable | slice, ...]
157-
),
150+
idx: list[str] | Index | Series[S1] | MaskType | tuple[Hashable | slice, ...],
158151
) -> generic.SeriesGroupBy: ...
159152
@overload
160153
def __getitem__(self: BaseGroupBy[Series[S1]], idx: Scalar) -> S1: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Index(IndexOpsMixin[S1]):
6666
__hash__: ClassVar[None] # type: ignore[assignment]
6767
# overloads with additional dtypes
6868
@overload
69-
def __new__( # type: ignore[overload-overlap]
69+
def __new__(
7070
cls,
7171
data: Sequence[int | np.integer] | IndexOpsMixin[int] | np_ndarray_anyint,
7272
*,
@@ -77,7 +77,7 @@ class Index(IndexOpsMixin[S1]):
7777
**kwargs,
7878
) -> Index[int]: ...
7979
@overload
80-
def __new__( # type: ignore[overload-overlap]
80+
def __new__(
8181
cls,
8282
data: Iterable,
8383
*,
@@ -88,7 +88,7 @@ class Index(IndexOpsMixin[S1]):
8888
**kwargs,
8989
) -> Index[int]: ...
9090
@overload
91-
def __new__( # type: ignore[overload-overlap]
91+
def __new__(
9292
cls,
9393
data: Sequence[float | np.floating] | IndexOpsMixin[float] | np_ndarray_float,
9494
*,
@@ -99,7 +99,7 @@ class Index(IndexOpsMixin[S1]):
9999
**kwargs,
100100
) -> Index[float]: ...
101101
@overload
102-
def __new__( # type: ignore[overload-overlap]
102+
def __new__(
103103
cls,
104104
data: Iterable,
105105
*,
@@ -110,7 +110,7 @@ class Index(IndexOpsMixin[S1]):
110110
**kwargs,
111111
) -> Index[float]: ...
112112
@overload
113-
def __new__( # type: ignore[overload-overlap]
113+
def __new__(
114114
cls,
115115
data: (
116116
Sequence[complex | np.complexfloating]
@@ -125,7 +125,7 @@ class Index(IndexOpsMixin[S1]):
125125
**kwargs,
126126
) -> Index[complex]: ...
127127
@overload
128-
def __new__( # type: ignore[overload-overlap]
128+
def __new__(
129129
cls,
130130
data: Iterable,
131131
*,
@@ -137,7 +137,7 @@ class Index(IndexOpsMixin[S1]):
137137
) -> Index[complex]: ...
138138
# special overloads with dedicated Index-subclasses
139139
@overload
140-
def __new__( # type: ignore[overload-overlap]
140+
def __new__(
141141
cls,
142142
data: Sequence[np.datetime64 | datetime] | IndexOpsMixin[datetime],
143143
*,
@@ -148,7 +148,7 @@ class Index(IndexOpsMixin[S1]):
148148
**kwargs,
149149
) -> DatetimeIndex: ...
150150
@overload
151-
def __new__( # type: ignore[overload-overlap]
151+
def __new__(
152152
cls,
153153
data: Iterable,
154154
*,
@@ -159,7 +159,7 @@ class Index(IndexOpsMixin[S1]):
159159
**kwargs,
160160
) -> DatetimeIndex: ...
161161
@overload
162-
def __new__( # type: ignore[overload-overlap]
162+
def __new__(
163163
cls,
164164
data: Sequence[Period] | IndexOpsMixin[Period],
165165
*,
@@ -170,7 +170,7 @@ class Index(IndexOpsMixin[S1]):
170170
**kwargs,
171171
) -> PeriodIndex: ...
172172
@overload
173-
def __new__( # type: ignore[overload-overlap]
173+
def __new__(
174174
cls,
175175
data: Iterable,
176176
*,
@@ -181,7 +181,7 @@ class Index(IndexOpsMixin[S1]):
181181
**kwargs,
182182
) -> PeriodIndex: ...
183183
@overload
184-
def __new__( # type: ignore[overload-overlap]
184+
def __new__(
185185
cls,
186186
data: Sequence[np.timedelta64 | timedelta] | IndexOpsMixin[timedelta],
187187
*,
@@ -192,7 +192,7 @@ class Index(IndexOpsMixin[S1]):
192192
**kwargs,
193193
) -> TimedeltaIndex: ...
194194
@overload
195-
def __new__( # type: ignore[overload-overlap]
195+
def __new__(
196196
cls,
197197
data: Iterable,
198198
*,
@@ -203,7 +203,7 @@ class Index(IndexOpsMixin[S1]):
203203
**kwargs,
204204
) -> TimedeltaIndex: ...
205205
@overload
206-
def __new__( # type: ignore[overload-overlap]
206+
def __new__(
207207
cls,
208208
data: Sequence[Interval[_OrderableT]] | IndexOpsMixin[Interval[_OrderableT]],
209209
*,
@@ -214,7 +214,7 @@ class Index(IndexOpsMixin[S1]):
214214
**kwargs,
215215
) -> IntervalIndex[Interval[_OrderableT]]: ...
216216
@overload
217-
def __new__( # type: ignore[overload-overlap]
217+
def __new__(
218218
cls,
219219
data: Iterable,
220220
*,
@@ -422,7 +422,7 @@ class Index(IndexOpsMixin[S1]):
422422
def __gt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
423423
# overwrite inherited methods from OpsMixin
424424
@overload
425-
def __mul__( # type: ignore[overload-overlap]
425+
def __mul__(
426426
self: Index[int] | Index[float], other: timedelta
427427
) -> TimedeltaIndex: ...
428428
@overload

pandas-stubs/core/indexes/interval.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class IntervalIndex(ExtensionIndex[IntervalT], IntervalMixin):
306306
# misc here because int and float overlap but interval has distinct types
307307
# int gets hit first and so the correct type is returned
308308
@overload
309-
def interval_range( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
309+
def interval_range( # pyright: ignore[reportOverlappingOverload]
310310
start: int = ...,
311311
end: int = ...,
312312
periods: int | None = ...,

pandas-stubs/core/reshape/concat.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from pandas._typing import (
2525
)
2626

2727
@overload
28-
def concat(
28+
def concat( # type: ignore[overload-overlap]
2929
objs: Iterable[DataFrame] | Mapping[HashableT1, DataFrame],
3030
*,
3131
axis: Axis = ...,

pandas-stubs/core/reshape/tile.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def cut(
5050
ordered: bool = ...,
5151
) -> tuple[npt.NDArray[np.intp], IntervalIndex[IntervalT]]: ...
5252
@overload
53-
def cut( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
53+
def cut( # pyright: ignore[reportOverlappingOverload]
5454
x: TimestampSeries,
5555
bins: (
5656
int

0 commit comments

Comments
 (0)