Skip to content

Commit 768b27f

Browse files
ganevgvjreback
authored andcommitted
add test for unused level raises KeyError (#29760)
1 parent d56c2dc commit 768b27f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/tests/test_multilevel.py

+11
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,17 @@ def test_stack_unstack_wrong_level_name(self, method):
583583
with pytest.raises(KeyError, match="does not match index name"):
584584
getattr(s, method)("mistake")
585585

586+
def test_unused_level_raises(self):
587+
# GH 20410
588+
mi = MultiIndex(
589+
levels=[["a_lot", "onlyone", "notevenone"], [1970, ""]],
590+
codes=[[1, 0], [1, 0]],
591+
)
592+
df = DataFrame(-1, index=range(3), columns=mi)
593+
594+
with pytest.raises(KeyError, match="notevenone"):
595+
df["notevenone"]
596+
586597
def test_unstack_level_name(self):
587598
result = self.frame.unstack("second")
588599
expected = self.frame.unstack(level=1)

0 commit comments

Comments
 (0)