Skip to content

TYP: Index._simple_new #50534

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

Merged
merged 1 commit into from
Jan 3, 2023
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: 3 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):
# See each method's docstring.

@classmethod
def _simple_new(cls: type[_IndexT], values, name: Hashable = None) -> _IndexT:
def _simple_new(
cls: type[_IndexT], values: ArrayLike, name: Hashable = None
) -> _IndexT:
"""
We require that we have a dtype compat for the values. If we are passed
a non-dtype compat, then coerce using the constructor.
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ def from_range(
cls._validate_dtype(dtype)
return cls._simple_new(data, name=name)

# error: Argument 1 of "_simple_new" is incompatible with supertype "Index";
# supertype defines the argument type as
# "Union[ExtensionArray, ndarray[Any, Any]]" [override]
@classmethod
def _simple_new(cls, values: range, name: Hashable = None) -> RangeIndex:
def _simple_new( # type: ignore[override]
cls, values: range, name: Hashable = None
) -> RangeIndex:
result = object.__new__(cls)

assert isinstance(values, range)
Expand Down