Skip to content

BUG: Indexing on nullable column #44551

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 5 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ Indexing
- Bug in :meth:`Series.__setitem__` with a boolean mask indexer setting a listlike value of length 1 incorrectly broadcasting that value (:issue:`44265`)
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`DataFrame.iloc.__setitem__` with mixed dtypes sometimes failing to operate in-place (:issue:`44345`)
- Bug in :meth:`DataFrame.loc.__getitem__` incorrectly raising ``KeyError`` when selecting a single column with a boolean key (:issue:`44322`).
- Bug in indexing on columns with ``loc`` or ``iloc`` using a slice with a negative step with ``ExtensionDtype`` columns incorrectly raising (:issue:`44551`)
-

Missing
^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,9 @@ def _slice(self, slicer) -> ExtensionArray:
)
# GH#32959 only full-slicers along fake-dim0 are valid
# TODO(EA2D): won't be necessary with 2D EAs
new_locs = self._mgr_locs[first]
# range(1) instead of self._mgr_locs to avoid exception on [::-1]
# see test_iloc_getitem_slice_negative_step_ea_block
new_locs = range(1)[first]
if len(new_locs):
# effectively slice(None)
slicer = slicer[1]
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,18 @@ def test_loc_setitem_boolean_list(self, rhs_func, indexing_func):
expected = DataFrame({"a": [5, 1, 10]})
tm.assert_frame_equal(df, expected)

def test_iloc_getitem_slice_negative_step_ea_block(self):
# GH#44551
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an additional Test for loc necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary, but harmless. will update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i take it back, will be a bit of a hassle to test loc, so leaving as-is

df = DataFrame({"A": [1, 2, 3]}, dtype="Int64")

res = df.iloc[:, ::-1]
tm.assert_frame_equal(res, df)

df["B"] = "foo"
res = df.iloc[:, ::-1]
expected = DataFrame({"B": df["B"], "A": df["A"]})
tm.assert_frame_equal(res, expected)


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