Skip to content

Commit fc6b441

Browse files
authored
BUG: Indexing on nullable column (#44551)
1 parent 81fa367 commit fc6b441

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v1.4.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ Indexing
621621
- Bug in :meth:`Series.__setitem__` with a boolean mask indexer setting a listlike value of length 1 incorrectly broadcasting that value (:issue:`44265`)
622622
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`DataFrame.iloc.__setitem__` with mixed dtypes sometimes failing to operate in-place (:issue:`44345`)
623623
- Bug in :meth:`DataFrame.loc.__getitem__` incorrectly raising ``KeyError`` when selecting a single column with a boolean key (:issue:`44322`).
624+
- Bug in indexing on columns with ``loc`` or ``iloc`` using a slice with a negative step with ``ExtensionDtype`` columns incorrectly raising (:issue:`44551`)
625+
-
624626

625627
Missing
626628
^^^^^^^

pandas/core/internals/blocks.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,9 @@ def _slice(self, slicer) -> ExtensionArray:
15661566
)
15671567
# GH#32959 only full-slicers along fake-dim0 are valid
15681568
# TODO(EA2D): won't be necessary with 2D EAs
1569-
new_locs = self._mgr_locs[first]
1569+
# range(1) instead of self._mgr_locs to avoid exception on [::-1]
1570+
# see test_iloc_getitem_slice_negative_step_ea_block
1571+
new_locs = range(1)[first]
15701572
if len(new_locs):
15711573
# effectively slice(None)
15721574
slicer = slicer[1]

pandas/tests/indexing/test_iloc.py

+12
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,18 @@ def test_loc_setitem_boolean_list(self, rhs_func, indexing_func):
11461146
expected = DataFrame({"a": [5, 1, 10]})
11471147
tm.assert_frame_equal(df, expected)
11481148

1149+
def test_iloc_getitem_slice_negative_step_ea_block(self):
1150+
# GH#44551
1151+
df = DataFrame({"A": [1, 2, 3]}, dtype="Int64")
1152+
1153+
res = df.iloc[:, ::-1]
1154+
tm.assert_frame_equal(res, df)
1155+
1156+
df["B"] = "foo"
1157+
res = df.iloc[:, ::-1]
1158+
expected = DataFrame({"B": df["B"], "A": df["A"]})
1159+
tm.assert_frame_equal(res, expected)
1160+
11491161

11501162
class TestILocErrors:
11511163
# NB: this test should work for _any_ Series we can pass as

0 commit comments

Comments
 (0)