Skip to content

Fix regression in .ix fallback with IntervalIndex #27926

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
Aug 19, 2019
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Indexing
- Bug in partial-string indexing returning a NumPy array rather than a ``Series`` when indexing with a scalar like ``.loc['2015']`` (:issue:`27516`)
- Break reference cycle involving :class:`Index` to allow garbage collection of :class:`Index` objects without running the GC. (:issue:`27585`)
- Fix regression in assigning values to a single column of a DataFrame with a ``MultiIndex`` columns (:issue:`27841`).
- Fix regression in ``.ix`` fallback with an ``IntervalIndex`` (:issue:`27865`).
-

Missing
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ def __getitem__(self, key):
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
try:
values = self.obj._get_value(*key)
except (KeyError, TypeError, InvalidIndexError):
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):
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexing/test_ix.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,13 @@ def test_ix_duplicate_returns_series(self):
r = df.ix[0.2, "a"]
e = df.loc[0.2, "a"]
tm.assert_series_equal(r, e)

def test_ix_intervalindex(self):
# https://github.com/pandas-dev/pandas/issues/27865
df = DataFrame(
np.random.randn(5, 2),
index=pd.IntervalIndex.from_breaks([-np.inf, 0, 1, 2, 3, np.inf]),
)
result = df.ix[0:2, 0]
expected = df.iloc[0:2, 0]
tm.assert_series_equal(result, expected)