Skip to content

Commit 0f048cb

Browse files
jbrockmendeljorisvandenbossche
authored andcommitted
CLN: remove geopandas compat code (#30909)
1 parent 13b22fd commit 0f048cb

File tree

2 files changed

+2
-91
lines changed

2 files changed

+2
-91
lines changed

pandas/core/indexing.py

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
is_list_like_indexer,
2828
length_of_indexer,
2929
)
30-
from pandas.core.indexes.api import Index, InvalidIndexError
30+
from pandas.core.indexes.api import Index
3131

3232
# "null slice"
3333
_NS = slice(None, None)
@@ -579,39 +579,6 @@ def __call__(self, axis=None):
579579
new_self.axis = axis
580580
return new_self
581581

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-
615582
def _get_label(self, label, axis: int):
616583
if self.ndim == 1:
617584
# for perf reasons we want to try _xs first
@@ -1460,42 +1427,6 @@ def _getitem_nested_tuple(self, tup: Tuple):
14601427

14611428
return obj
14621429

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-
14991430
def _get_listlike_indexer(self, key, axis: int, raise_missing: bool = False):
15001431
"""
15011432
Transform a list-like of keys into a new index and an indexer.

pandas/tests/test_downstream.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np # noqa
99
import pytest
1010

11-
from pandas import DataFrame, Series
11+
from pandas import DataFrame
1212
import pandas._testing as tm
1313

1414

@@ -114,26 +114,6 @@ def test_geopandas():
114114
assert geopandas.read_file(fp) is not None
115115

116116

117-
def test_geopandas_coordinate_indexer():
118-
# this test is included to have coverage of one case in the indexing.py
119-
# code that is only kept for compatibility with geopandas, see
120-
# https://github.com/pandas-dev/pandas/issues/27258
121-
# We should be able to remove this after some time when its usage is
122-
# removed in geopandas
123-
from pandas.core.indexing import _NDFrameIndexer
124-
125-
class _CoordinateIndexer(_NDFrameIndexer):
126-
def _getitem_tuple(self, tup):
127-
obj = self.obj
128-
xs, ys = tup
129-
return obj[xs][ys]
130-
131-
Series._create_indexer("cx", _CoordinateIndexer)
132-
s = Series(range(5))
133-
res = s.cx[:, :]
134-
tm.assert_series_equal(s, res)
135-
136-
137117
# Cython import warning
138118
@pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning")
139119
@pytest.mark.filterwarnings("ignore:RangeIndex.* is deprecated:DeprecationWarning")

0 commit comments

Comments
 (0)