Skip to content

Commit c64c9cb

Browse files
jorisvandenbosscheTomAugspurger
authored andcommitted
TST: Add comment and test for geopandas compat fix (GH27259) (#27287)
1 parent 3c78b2f commit c64c9cb

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pandas/core/indexing.py

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def __getitem__(self, key):
123123
# generally slice or list.
124124
# TODO(ix): most/all of the TypeError cases here are for ix,
125125
# so this check can be removed once ix is removed.
126+
# The InvalidIndexError is only catched for compatibility
127+
# with geopandas, see
128+
# https://github.com/pandas-dev/pandas/issues/27258
126129
pass
127130
else:
128131
if is_scalar(values):

pandas/tests/test_downstream.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from pandas.compat import PY36
1212

13-
from pandas import DataFrame
13+
from pandas import DataFrame, Series
1414
from pandas.util import testing as tm
1515

1616

@@ -123,6 +123,26 @@ def test_geopandas():
123123
assert geopandas.read_file(fp) is not None
124124

125125

126+
def test_geopandas_coordinate_indexer():
127+
# this test is included to have coverage of one case in the indexing.py
128+
# code that is only kept for compatibility with geopandas, see
129+
# https://github.com/pandas-dev/pandas/issues/27258
130+
# We should be able to remove this after some time when its usage is
131+
# removed in geopandas
132+
from pandas.core.indexing import _NDFrameIndexer
133+
134+
class _CoordinateIndexer(_NDFrameIndexer):
135+
def _getitem_tuple(self, tup):
136+
obj = self.obj
137+
xs, ys = tup
138+
return obj[xs][ys]
139+
140+
Series._create_indexer("cx", _CoordinateIndexer)
141+
s = Series(range(5))
142+
res = s.cx[:, :]
143+
tm.assert_series_equal(s, res)
144+
145+
126146
# Cython import warning
127147
@pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning")
128148
def test_pyarrow(df):

0 commit comments

Comments
 (0)