Skip to content

TST: add test for unused level indexing raises KeyError #29760

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
Nov 22, 2019
Merged
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
11 changes: 11 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ def test_stack_unstack_wrong_level_name(self, method):
with pytest.raises(KeyError, match="does not match index name"):
getattr(s, method)("mistake")

def test_unused_level_raises(self):
# GH 20410
mi = MultiIndex(
levels=[["a_lot", "onlyone", "notevenone"], [1970, ""]],
codes=[[1, 0], [1, 0]],
)
df = DataFrame(-1, index=range(3), columns=mi)

with pytest.raises(KeyError, match="notevenone"):
df["notevenone"]

def test_unstack_level_name(self):
result = self.frame.unstack("second")
expected = self.frame.unstack(level=1)
Expand Down