|
27 | 27 | is_list_like_indexer,
|
28 | 28 | length_of_indexer,
|
29 | 29 | )
|
30 |
| -from pandas.core.indexes.api import Index, InvalidIndexError |
| 30 | +from pandas.core.indexes.api import Index |
31 | 31 |
|
32 | 32 | # "null slice"
|
33 | 33 | _NS = slice(None, None)
|
@@ -579,39 +579,6 @@ def __call__(self, axis=None):
|
579 | 579 | new_self.axis = axis
|
580 | 580 | return new_self
|
581 | 581 |
|
582 |
| - # TODO: remove once geopandas no longer needs this |
583 |
| - def __getitem__(self, key): |
584 |
| - # Used in ix and downstream in geopandas _CoordinateIndexer |
585 |
| - if type(key) is tuple: |
586 |
| - # Note: we check the type exactly instead of with isinstance |
587 |
| - # because NamedTuple is checked separately. |
588 |
| - key = tuple(com.apply_if_callable(x, self.obj) for x in key) |
589 |
| - try: |
590 |
| - values = self.obj._get_value(*key) |
591 |
| - except (KeyError, TypeError, InvalidIndexError, AttributeError): |
592 |
| - # TypeError occurs here if the key has non-hashable entries, |
593 |
| - # generally slice or list. |
594 |
| - # TODO(ix): most/all of the TypeError cases here are for ix, |
595 |
| - # so this check can be removed once ix is removed. |
596 |
| - # The InvalidIndexError is only catched for compatibility |
597 |
| - # with geopandas, see |
598 |
| - # https://github.com/pandas-dev/pandas/issues/27258 |
599 |
| - # TODO: The AttributeError is for IntervalIndex which |
600 |
| - # incorrectly implements get_value, see |
601 |
| - # https://github.com/pandas-dev/pandas/issues/27865 |
602 |
| - pass |
603 |
| - else: |
604 |
| - if is_scalar(values): |
605 |
| - return values |
606 |
| - |
607 |
| - return self._getitem_tuple(key) |
608 |
| - else: |
609 |
| - # we by definition only have the 0th axis |
610 |
| - axis = self.axis or 0 |
611 |
| - |
612 |
| - key = com.apply_if_callable(key, self.obj) |
613 |
| - return self._getitem_axis(key, axis=axis) |
614 |
| - |
615 | 582 | def _get_label(self, label, axis: int):
|
616 | 583 | if self.ndim == 1:
|
617 | 584 | # for perf reasons we want to try _xs first
|
@@ -1460,42 +1427,6 @@ def _getitem_nested_tuple(self, tup: Tuple):
|
1460 | 1427 |
|
1461 | 1428 | return obj
|
1462 | 1429 |
|
1463 |
| - # TODO: remove once geopandas no longer needs __getitem__ |
1464 |
| - def _getitem_axis(self, key, axis: int): |
1465 |
| - if is_iterator(key): |
1466 |
| - key = list(key) |
1467 |
| - self._validate_key(key, axis) |
1468 |
| - |
1469 |
| - labels = self.obj._get_axis(axis) |
1470 |
| - if isinstance(key, slice): |
1471 |
| - return self._get_slice_axis(key, axis=axis) |
1472 |
| - elif is_list_like_indexer(key) and not ( |
1473 |
| - isinstance(key, tuple) and isinstance(labels, ABCMultiIndex) |
1474 |
| - ): |
1475 |
| - |
1476 |
| - if hasattr(key, "ndim") and key.ndim > 1: |
1477 |
| - raise ValueError("Cannot index with multidimensional key") |
1478 |
| - |
1479 |
| - return self._getitem_iterable(key, axis=axis) |
1480 |
| - else: |
1481 |
| - |
1482 |
| - # maybe coerce a float scalar to integer |
1483 |
| - key = labels._maybe_cast_indexer(key) |
1484 |
| - |
1485 |
| - if is_integer(key): |
1486 |
| - if axis == 0 and isinstance(labels, ABCMultiIndex): |
1487 |
| - try: |
1488 |
| - return self._get_label(key, axis=axis) |
1489 |
| - except (KeyError, TypeError): |
1490 |
| - if self.obj.index.levels[0].is_integer(): |
1491 |
| - raise |
1492 |
| - |
1493 |
| - # this is the fallback! (for a non-float, non-integer index) |
1494 |
| - if not labels.is_floating() and not labels.is_integer(): |
1495 |
| - return self._get_loc(key, axis=axis) |
1496 |
| - |
1497 |
| - return self._get_label(key, axis=axis) |
1498 |
| - |
1499 | 1430 | def _get_listlike_indexer(self, key, axis: int, raise_missing: bool = False):
|
1500 | 1431 | """
|
1501 | 1432 | Transform a list-like of keys into a new index and an indexer.
|
|
0 commit comments