diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index c30885291ffc9..2566f05daeaea 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -123,6 +123,9 @@ def __getitem__(self, key): # generally slice or list. # TODO(ix): most/all of the TypeError cases here are for ix, # so this check can be removed once ix is removed. + # The InvalidIndexError is only catched for compatibility + # with geopandas, see + # https://github.com/pandas-dev/pandas/issues/27258 pass else: if is_scalar(values): diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index d644c002fbdfb..93baafddedeb4 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -10,7 +10,7 @@ from pandas.compat import PY36 -from pandas import DataFrame +from pandas import DataFrame, Series from pandas.util import testing as tm @@ -123,6 +123,26 @@ def test_geopandas(): assert geopandas.read_file(fp) is not None +def test_geopandas_coordinate_indexer(): + # this test is included to have coverage of one case in the indexing.py + # code that is only kept for compatibility with geopandas, see + # https://github.com/pandas-dev/pandas/issues/27258 + # We should be able to remove this after some time when its usage is + # removed in geopandas + from pandas.core.indexing import _NDFrameIndexer + + class _CoordinateIndexer(_NDFrameIndexer): + def _getitem_tuple(self, tup): + obj = self.obj + xs, ys = tup + return obj[xs][ys] + + Series._create_indexer("cx", _CoordinateIndexer) + s = Series(range(5)) + res = s.cx[:, :] + tm.assert_series_equal(s, res) + + # Cython import warning @pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning") def test_pyarrow(df):