Skip to content

Commit 325dd68

Browse files
jorisvandenbosscheTomAugspurger
authored andcommitted
Fix regression in .ix fallback with IntervalIndex (#27926)
1 parent a4b0132 commit 325dd68

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.25.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Indexing
8484
- Bug in partial-string indexing returning a NumPy array rather than a ``Series`` when indexing with a scalar like ``.loc['2015']`` (:issue:`27516`)
8585
- Break reference cycle involving :class:`Index` and other index classes to allow garbage collection of index objects without running the GC. (:issue:`27585`, :issue:`27840`)
8686
- Fix regression in assigning values to a single column of a DataFrame with a ``MultiIndex`` columns (:issue:`27841`).
87+
- Fix regression in ``.ix`` fallback with an ``IntervalIndex`` (:issue:`27865`).
8788
-
8889

8990
Missing

pandas/core/indexing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,17 @@ def __getitem__(self, key):
124124
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
125125
try:
126126
values = self.obj._get_value(*key)
127-
except (KeyError, TypeError, InvalidIndexError):
127+
except (KeyError, TypeError, InvalidIndexError, AttributeError):
128128
# TypeError occurs here if the key has non-hashable entries,
129129
# generally slice or list.
130130
# TODO(ix): most/all of the TypeError cases here are for ix,
131131
# so this check can be removed once ix is removed.
132132
# The InvalidIndexError is only catched for compatibility
133133
# with geopandas, see
134134
# https://github.com/pandas-dev/pandas/issues/27258
135+
# TODO: The AttributeError is for IntervalIndex which
136+
# incorrectly implements get_value, see
137+
# https://github.com/pandas-dev/pandas/issues/27865
135138
pass
136139
else:
137140
if is_scalar(values):

pandas/tests/indexing/test_ix.py

+10
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,13 @@ def test_ix_duplicate_returns_series(self):
343343
r = df.ix[0.2, "a"]
344344
e = df.loc[0.2, "a"]
345345
tm.assert_series_equal(r, e)
346+
347+
def test_ix_intervalindex(self):
348+
# https://github.com/pandas-dev/pandas/issues/27865
349+
df = DataFrame(
350+
np.random.randn(5, 2),
351+
index=pd.IntervalIndex.from_breaks([-np.inf, 0, 1, 2, 3, np.inf]),
352+
)
353+
result = df.ix[0:2, 0]
354+
expected = df.iloc[0:2, 0]
355+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)