Skip to content

Commit

Permalink
add test for unused level raises KeyError (pandas-dev#29760)
Browse files Browse the repository at this point in the history
  • Loading branch information
ganevgv authored and proost committed Dec 19, 2019
1 parent fbcfd98 commit b728ab9
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit b728ab9

Please sign in to comment.