Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix slice/Hashable overlap. Update mypy and pyright #1021

Merged
merged 4 commits into from
Nov 1, 2024
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
4 changes: 2 additions & 2 deletions pandas-stubs/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
@overload
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __ne__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Timedelta(timedelta):
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
# maybe related to https://github.com/python/mypy/issues/10755
@overload
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ... # type: ignore[misc]
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
# Override due to more types supported than dt.timedelta
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
@overload # type: ignore[override]
Expand Down
6 changes: 4 additions & 2 deletions pandas-stubs/core/algorithms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ from pandas._typing import (
# with extension types return the same type while standard type return ndarray

@overload
def unique(values: PeriodIndex) -> PeriodIndex: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def unique( # pyright: ignore[reportOverlappingOverload]
values: PeriodIndex,
) -> PeriodIndex: ...
@overload
def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[overload-overlap]
@overload
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... # type: ignore[overload-overlap]
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ...
@overload
def unique(values: Index) -> np.ndarray: ...
@overload
Expand Down
9 changes: 0 additions & 9 deletions pandas-stubs/core/arrays/datetimelike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,7 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
def resolution(self): ...
__pow__ = ...
__rpow__ = ...
__mul__ = ...
__rmul__ = ...
__truediv__ = ...
__rtruediv__ = ...
__floordiv__ = ...
__rfloordiv__ = ...
__mod__ = ...
__rmod__ = ...
__divmod__ = ...
__rdivmod__ = ...
twoertwein marked this conversation as resolved.
Show resolved Hide resolved
def __add__(self, other): ...
def __radd__(self, other): ...
def __sub__(self, other): ...
Expand Down
22 changes: 11 additions & 11 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class _LocIndexerFrame(_LocIndexer):
),
) -> DataFrame: ...
@overload
def __getitem__( # pyright: ignore[reportOverlappingOverload]
def __getitem__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self,
idx: tuple[
int | StrLike | tuple[Scalar, ...] | Callable[[DataFrame], ScalarT],
Expand Down Expand Up @@ -307,7 +307,7 @@ class DataFrame(NDFrame, OpsMixin):
na_value: Scalar = ...,
) -> np.ndarray: ...
@overload
def to_dict( # type: ignore[overload-overlap]
def to_dict(
self,
orient: Literal["records"],
*,
Expand All @@ -323,31 +323,31 @@ class DataFrame(NDFrame, OpsMixin):
index: Literal[True] = ...,
) -> list[dict[Hashable, Any]]: ...
@overload
def to_dict( # type: ignore[overload-overlap]
def to_dict(
self,
orient: Literal["dict", "list", "series", "index"],
*,
into: MutableMapping | type[MutableMapping],
index: Literal[True] = ...,
) -> MutableMapping[Hashable, Any]: ...
@overload
def to_dict( # type: ignore[overload-overlap]
def to_dict(
self,
orient: Literal["split", "tight"],
*,
into: MutableMapping | type[MutableMapping],
index: bool = ...,
) -> MutableMapping[Hashable, Any]: ...
@overload
def to_dict( # type: ignore[overload-overlap]
def to_dict(
self,
orient: Literal["dict", "list", "series", "index"] = ...,
*,
into: MutableMapping | type[MutableMapping],
index: Literal[True] = ...,
) -> MutableMapping[Hashable, Any]: ...
@overload
def to_dict( # type: ignore[overload-overlap]
def to_dict(
self,
orient: Literal["split", "tight"] = ...,
*,
Expand Down Expand Up @@ -1054,7 +1054,7 @@ class DataFrame(NDFrame, OpsMixin):
errors: IgnoreRaise = ...,
) -> None: ...
@overload
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
def groupby( # pyright: ignore reportOverlappingOverload
self,
by: Scalar,
axis: AxisIndex | NoDefault = ...,
Expand All @@ -1078,7 +1078,7 @@ class DataFrame(NDFrame, OpsMixin):
dropna: _bool = ...,
) -> DataFrameGroupBy[Scalar, Literal[False]]: ...
@overload
def groupby( # type: ignore[overload-overlap] # pyright: ignore reportOverlappingOverload
def groupby( # pyright: ignore reportOverlappingOverload
self,
by: DatetimeIndex,
axis: AxisIndex | NoDefault = ...,
Expand All @@ -1090,7 +1090,7 @@ class DataFrame(NDFrame, OpsMixin):
dropna: _bool = ...,
) -> DataFrameGroupBy[Timestamp, Literal[True]]: ...
@overload
def groupby( # type: ignore[overload-overlap]
def groupby(
self,
by: DatetimeIndex,
axis: AxisIndex | NoDefault = ...,
Expand Down Expand Up @@ -1219,7 +1219,7 @@ class DataFrame(NDFrame, OpsMixin):
) -> DataFrame: ...
def diff(self, periods: int = ..., axis: Axis = ...) -> DataFrame: ...
@overload
def agg( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def agg( # pyright: ignore[reportOverlappingOverload]
self, func: AggFuncTypeBase | AggFuncTypeDictSeries, axis: Axis = ..., **kwargs
) -> Series: ...
@overload
Expand All @@ -1230,7 +1230,7 @@ class DataFrame(NDFrame, OpsMixin):
**kwargs,
) -> DataFrame: ...
@overload
def aggregate( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def aggregate( # pyright: ignore[reportOverlappingOverload]
self, func: AggFuncTypeBase | AggFuncTypeDictSeries, axis: Axis = ..., **kwargs
) -> Series: ...
@overload
Expand Down
12 changes: 5 additions & 7 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ _TT = TypeVar("_TT", bound=Literal[True, False])
class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
# error: Overload 3 for "apply" will never be used because its parameters overlap overload 1
@overload # type: ignore[override]
def apply( # type: ignore[overload-overlap]
def apply(
self,
func: Callable[[DataFrame], Scalar | list | dict],
*args,
Expand Down Expand Up @@ -234,12 +234,10 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
self, func: Callable, dropna: bool = ..., *args, **kwargs
) -> DataFrame: ...
@overload
def __getitem__( # type: ignore[overload-overlap]
self, key: Scalar | Hashable | tuple[Hashable, ...]
) -> SeriesGroupBy[Any, ByT]: ...
def __getitem__(self, key: Scalar) -> SeriesGroupBy[Any, ByT]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride, reportOverlappingOverload]
self, key: Iterable[Hashable] | slice
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride]
self, key: Iterable[Hashable]
twoertwein marked this conversation as resolved.
Show resolved Hide resolved
) -> DataFrameGroupBy[ByT, bool]: ...
def nunique(self, dropna: bool = ...) -> DataFrame: ...
def idxmax(
Expand Down Expand Up @@ -324,7 +322,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
self, indices: TakeIndexer, axis: Axis | None | NoDefault = ..., **kwargs
) -> DataFrame: ...
@overload
def skew( # type: ignore[overload-overlap]
def skew(
self,
axis: Axis | None | NoDefault = ...,
skipna: bool = ...,
Expand Down
15 changes: 4 additions & 11 deletions pandas-stubs/core/groupby/groupby.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,15 @@ class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
@final
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ...
@overload
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar | Hashable | tuple[Hashable, ...]) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap]
twoertwein marked this conversation as resolved.
Show resolved Hide resolved
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __getitem__( # pyright: ignore[reportOverlappingOverload]
self: BaseGroupBy[DataFrame], key: Iterable[Hashable] | slice
def __getitem__(
self: BaseGroupBy[DataFrame], key: Iterable[Hashable]
) -> generic.DataFrameGroupBy: ...
@overload
def __getitem__(
self: BaseGroupBy[Series[S1]],
idx: (
list[str]
| Index
| Series[S1]
| slice
| MaskType
| tuple[Hashable | slice, ...]
),
idx: list[str] | Index | Series[S1] | MaskType | tuple[Hashable | slice, ...],
) -> generic.SeriesGroupBy: ...
@overload
def __getitem__(self: BaseGroupBy[Series[S1]], idx: Scalar) -> S1: ...
Expand Down
30 changes: 15 additions & 15 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Index(IndexOpsMixin[S1]):
__hash__: ClassVar[None] # type: ignore[assignment]
# overloads with additional dtypes
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Sequence[int | np.integer] | IndexOpsMixin[int] | np_ndarray_anyint,
*,
Expand All @@ -77,7 +77,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> Index[int]: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand All @@ -88,7 +88,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> Index[int]: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Sequence[float | np.floating] | IndexOpsMixin[float] | np_ndarray_float,
*,
Expand All @@ -99,7 +99,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> Index[float]: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand All @@ -110,7 +110,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> Index[float]: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: (
Sequence[complex | np.complexfloating]
Expand All @@ -125,7 +125,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> Index[complex]: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand All @@ -137,7 +137,7 @@ class Index(IndexOpsMixin[S1]):
) -> Index[complex]: ...
# special overloads with dedicated Index-subclasses
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Sequence[np.datetime64 | datetime] | IndexOpsMixin[datetime],
*,
Expand All @@ -148,7 +148,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> DatetimeIndex: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand All @@ -159,7 +159,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> DatetimeIndex: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Sequence[Period] | IndexOpsMixin[Period],
*,
Expand All @@ -170,7 +170,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> PeriodIndex: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand All @@ -181,7 +181,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> PeriodIndex: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Sequence[np.timedelta64 | timedelta] | IndexOpsMixin[timedelta],
*,
Expand All @@ -192,7 +192,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> TimedeltaIndex: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand All @@ -203,7 +203,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> TimedeltaIndex: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Sequence[Interval[_OrderableT]] | IndexOpsMixin[Interval[_OrderableT]],
*,
Expand All @@ -214,7 +214,7 @@ class Index(IndexOpsMixin[S1]):
**kwargs,
) -> IntervalIndex[Interval[_OrderableT]]: ...
@overload
def __new__( # type: ignore[overload-overlap]
def __new__(
cls,
data: Iterable,
*,
Expand Down Expand Up @@ -422,7 +422,7 @@ class Index(IndexOpsMixin[S1]):
def __gt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
# overwrite inherited methods from OpsMixin
@overload
def __mul__( # type: ignore[overload-overlap]
def __mul__(
self: Index[int] | Index[float], other: timedelta
) -> TimedeltaIndex: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class IntervalIndex(ExtensionIndex[IntervalT], IntervalMixin):
# misc here because int and float overlap but interval has distinct types
# int gets hit first and so the correct type is returned
@overload
def interval_range( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def interval_range( # pyright: ignore[reportOverlappingOverload]
start: int = ...,
end: int = ...,
periods: int | None = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/reshape/concat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ from pandas._typing import (
)

@overload
def concat(
def concat( # type: ignore[overload-overlap]
objs: Iterable[DataFrame] | Mapping[HashableT1, DataFrame],
*,
axis: Axis = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/reshape/tile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def cut(
ordered: bool = ...,
) -> tuple[npt.NDArray[np.intp], IntervalIndex[IntervalT]]: ...
@overload
def cut( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def cut( # pyright: ignore[reportOverlappingOverload]
x: TimestampSeries,
bins: (
int
Expand Down
Loading
Loading