Skip to content

BUG: df.iloc[:, :1] with EA column #32959

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 15 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,11 @@ def _slice(self, slicer):
if not com.is_null_slice(slicer[0]):
raise AssertionError("invalid slicing for a 1-ndim categorical")
slicer = slicer[1]
elif not isinstance(slicer, tuple) and self.ndim == 2:
# reached via getitem_block via _slice_take_blocks_ax0
# TODO(EA2D): wont be necessary with 2D EAs
# treat this like (slicer, slice(None)
slicer = slice(None)

return self.values[slicer]

Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/extension/base/getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def test_iloc_frame(self, data):
result = df.iloc[:4, 0]
self.assert_series_equal(result, expected)

# GH#32957 null slice along index, slice along rows
result = df.iloc[:, :1]
self.assert_frame_equal(result, df[["A"]])

def test_loc_series(self, data):
ser = pd.Series(data)
result = ser.loc[:3]
Expand Down