Skip to content

BUG: getitem indexing wrong axis #54641

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 21, 2023
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
3 changes: 2 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,9 @@ def _getitem_tuple_same_dim(self, tup: tuple):
"""
retval = self.obj
# Selecting columns before rows is signficiantly faster
start_val = (self.ndim - len(tup)) + 1
for i, key in enumerate(reversed(tup)):
i = self.ndim - i - 1
i = self.ndim - i - start_val
if com.is_null_slice(key):
continue

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/indexing/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ def test_getitem_datetime_slice(self):
):
df["2011-01-01":"2011-11-01"]

def test_getitem_slice_same_dim_only_one_axis(self):
# GH#54622
df = DataFrame(np.random.default_rng(2).standard_normal((10, 8)))
result = df.iloc[(slice(None, None, 2),)]
assert result.shape == (5, 8)
expected = df.iloc[slice(None, None, 2), slice(None)]
tm.assert_frame_equal(result, expected)


class TestGetitemDeprecatedIndexers:
@pytest.mark.parametrize("key", [{"a", "b"}, {"a": "a"}])
Expand Down