Skip to content

CI: fix mypy error #37913

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

Closed
Closed
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
19 changes: 7 additions & 12 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Any,
Callable,
FrozenSet,
Generic,
Hashable,
List,
NewType,
Expand All @@ -27,7 +28,7 @@
from pandas._libs.lib import is_datetime_array, no_default
from pandas._libs.tslibs import IncompatibleFrequency, OutOfBoundsDatetime, Timestamp
from pandas._libs.tslibs.timezones import tz_compare
from pandas._typing import AnyArrayLike, Dtype, DtypeObj, Label, Shape, final
from pandas._typing import AnyArrayLike, ArrayLike, Dtype, DtypeObj, Label, Shape, final
from pandas.compat.numpy import function as nv
from pandas.errors import DuplicateLabelError, InvalidIndexError
from pandas.util._decorators import Appender, cache_readonly, doc
Expand Down Expand Up @@ -147,7 +148,7 @@ def _new_Index(cls, d):
_IndexT = TypeVar("_IndexT", bound="Index")


class Index(IndexOpsMixin, PandasObject):
class Index(IndexOpsMixin, PandasObject, Generic[ArrayLike]):
"""
Immutable sequence used for indexing and alignment. The basic object
storing axis labels for all pandas objects.
Expand Down Expand Up @@ -219,7 +220,7 @@ def _outer_indexer(self, left, right):
return libjoin.outer_join_indexer(left, right)

_typ = "index"
_data: Union[ExtensionArray, np.ndarray]
_data: ArrayLike
_id: Optional[_Identity] = None
_name: Label = None
# MultiIndex.levels previously allowed setting the index name. We
Expand Down Expand Up @@ -3222,14 +3223,8 @@ def _get_nearest_indexer(self, target: "Index", limit, tolerance) -> np.ndarray:
right_indexer = self.get_indexer(target, "backfill", limit=limit)

target_values = target._values
# error: Unsupported left operand type for - ("ExtensionArray")
left_distances = np.abs(
self._values[left_indexer] - target_values # type: ignore[operator]
)
# error: Unsupported left operand type for - ("ExtensionArray")
right_distances = np.abs(
self._values[right_indexer] - target_values # type: ignore[operator]
)
left_distances = np.abs(self._values[left_indexer] - target_values)
right_distances = np.abs(self._values[right_indexer] - target_values)

op = operator.lt if self.is_monotonic_increasing else operator.le
indexer = np.where(
Expand Down Expand Up @@ -4022,7 +4017,7 @@ def array(self) -> ExtensionArray:
return array

@property
def _values(self) -> Union[ExtensionArray, np.ndarray]:
def _values(self) -> ArrayLike:
"""
The best array representation.

Expand Down