Skip to content

TST: More old issues #41697

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 11 commits into from
May 28, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test for GH 20951
  • Loading branch information
mroeschke committed May 28, 2021
commit 35f3b657ac52719dd6c79a1e8b167f6c9b423257
15 changes: 15 additions & 0 deletions pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,3 +875,18 @@ def test_loc_empty_single_selector_with_names():
result = s2.loc["a"]
expected = Series([np.nan, np.nan], index=Index(["A", "B"], name=0))
tm.assert_series_equal(result, expected)


def test_loc_keyerror_rightmost_key_missing():
# GH 20951

df = DataFrame(
{
"A": [100, 100, 200, 200, 300, 300],
"B": [10, 10, 20, 21, 31, 33],
"C": range(6),
}
)
df = df.set_index(["A", "B"])
with pytest.raises(KeyError, match="1"):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
with pytest.raises(KeyError, match="1"):
with pytest.raises(KeyError, match="^1$"):

df.loc[(100, 1)]