Skip to content

TYP: Specify specific type for NumericIndex._values #41073

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 2 commits into from
Apr 21, 2021
Merged
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
10 changes: 3 additions & 7 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class NumericIndex(Index):
This is an abstract class.
"""

_values: np.ndarray
_default_dtype: np.dtype

_is_numeric_dtype = True
Expand Down Expand Up @@ -253,9 +254,7 @@ def asi8(self) -> np.ndarray:
FutureWarning,
stacklevel=2,
)
# error: Incompatible return value type (got "Union[ExtensionArray, ndarray]",
# expected "ndarray")
return self._values.view(self._default_dtype) # type: ignore[return-value]
return self._values.view(self._default_dtype)


class Int64Index(IntegerIndex):
Expand Down Expand Up @@ -330,10 +329,7 @@ def astype(self, dtype, copy=True):
elif is_integer_dtype(dtype) and not is_extension_array_dtype(dtype):
# TODO(jreback); this can change once we have an EA Index type
# GH 13149

# error: Argument 1 to "astype_nansafe" has incompatible type
# "Union[ExtensionArray, ndarray]"; expected "ndarray"
arr = astype_nansafe(self._values, dtype=dtype) # type: ignore[arg-type]
arr = astype_nansafe(self._values, dtype=dtype)
return Int64Index(arr, name=self.name)
return super().astype(dtype, copy=copy)

Expand Down