Skip to content

TST: changed behavior of df.loc on multiindex #43879

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

Closed
wants to merge 11 commits into from
Closed
11 changes: 11 additions & 0 deletions pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,14 @@ def test_loc_keyerror_rightmost_key_missing():
df = df.set_index(["A", "B"])
with pytest.raises(KeyError, match="^1$"):
df.loc[(100, 1)]
def test_loc_multiindex():
Copy link
Contributor

Choose a reason for hiding this comment

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

need a blank line between functions or this will fail linting

Copy link
Contributor

Choose a reason for hiding this comment

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

can you be more specific on the naem

and add the issue number as a commetn

df = DataFrame(
index=MultiIndex.from_product([list("abc"), list("de"), list("f")]),
columns=["Val"],
)
result = df.loc[np.s_[:, "d", :]]
expected = DataFrame(
index=MultiIndex.from_product([list("abc"), list("d"), list("f")]),
columns=["Val"],
)
tm.assert_frame_equal(result, expected)
5 changes: 5 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from pandas.tests.indexing.common import Base



Copy link
Contributor

Choose a reason for hiding this comment

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

can you revert these

class TestLoc(Base):
def test_loc_getitem_int(self):

Expand Down Expand Up @@ -2857,3 +2858,7 @@ def test_loc_set_multiple_items_in_multiple_new_columns(self):
)

tm.assert_frame_equal(df, expected)