Skip to content

CLN: remove geopandas compat code #30909

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

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
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
71 changes: 1 addition & 70 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is_list_like_indexer,
length_of_indexer,
)
from pandas.core.indexes.api import Index, InvalidIndexError
from pandas.core.indexes.api import Index

# "null slice"
_NS = slice(None, None)
Expand Down Expand Up @@ -579,39 +579,6 @@ def __call__(self, axis=None):
new_self.axis = axis
return new_self

# TODO: remove once geopandas no longer needs this
def __getitem__(self, key):
# Used in ix and downstream in geopandas _CoordinateIndexer
if type(key) is tuple:
# Note: we check the type exactly instead of with isinstance
# because NamedTuple is checked separately.
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
try:
values = self.obj._get_value(*key)
except (KeyError, TypeError, InvalidIndexError, AttributeError):
# TypeError occurs here if the key has non-hashable entries,
# 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
# TODO: The AttributeError is for IntervalIndex which
# incorrectly implements get_value, see
# https://github.com/pandas-dev/pandas/issues/27865
pass
else:
if is_scalar(values):
return values

return self._getitem_tuple(key)
else:
# we by definition only have the 0th axis
axis = self.axis or 0

key = com.apply_if_callable(key, self.obj)
return self._getitem_axis(key, axis=axis)

def _get_label(self, label, axis: int):
if self.ndim == 1:
# for perf reasons we want to try _xs first
Expand Down Expand Up @@ -1463,42 +1430,6 @@ def _getitem_nested_tuple(self, tup: Tuple):

return obj

# TODO: remove once geopandas no longer needs __getitem__
def _getitem_axis(self, key, axis: int):
if is_iterator(key):
key = list(key)
self._validate_key(key, axis)

labels = self.obj._get_axis(axis)
if isinstance(key, slice):
return self._get_slice_axis(key, axis=axis)
elif is_list_like_indexer(key) and not (
isinstance(key, tuple) and isinstance(labels, ABCMultiIndex)
):

if hasattr(key, "ndim") and key.ndim > 1:
raise ValueError("Cannot index with multidimensional key")

return self._getitem_iterable(key, axis=axis)
else:

# maybe coerce a float scalar to integer
key = labels._maybe_cast_indexer(key)

if is_integer(key):
if axis == 0 and isinstance(labels, ABCMultiIndex):
try:
return self._get_label(key, axis=axis)
except (KeyError, TypeError):
if self.obj.index.levels[0].is_integer():
raise

# this is the fallback! (for a non-float, non-integer index)
if not labels.is_floating() and not labels.is_integer():
return self._get_loc(key, axis=axis)

return self._get_label(key, axis=axis)

def _get_listlike_indexer(self, key, axis: int, raise_missing: bool = False):
"""
Transform a list-like of keys into a new index and an indexer.
Expand Down
22 changes: 1 addition & 21 deletions pandas/tests/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np # noqa
import pytest

from pandas import DataFrame, Series
from pandas import DataFrame
import pandas._testing as tm


Expand Down Expand Up @@ -114,26 +114,6 @@ 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")
@pytest.mark.filterwarnings("ignore:RangeIndex.* is deprecated:DeprecationWarning")
Expand Down