Skip to content

Commit

Permalink
Test case dataframe.groupby incorrect with multiindex and None value (p…
Browse files Browse the repository at this point in the history
…andas-dev#45982)

* Add test

* Update test_indexing.py

* Update test_indexing.py

* Update pytest.raises

* add match

* change function
  • Loading branch information
Khor Chean Wei authored Feb 16, 2022
1 parent cf2dfa7 commit 6cd6069
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pandas/tests/groupby/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,19 @@ def test_groupby_duplicated_columns(func):
[[1.5, 3.0, 1.5]], columns=["A", "B", "A"], index=pd.Index(["G"], name="C")
)
tm.assert_frame_equal(result, expected)


def test_groupby_get_nonexisting_groups():
# GH#32492
df = pd.DataFrame(
data={
"A": ["a1", "a2", None],
"B": ["b1", "b2", "b1"],
"val": [1, 2, 3],
}
)
grps = df.groupby(by=["A", "B"])

msg = "('a2', 'b1')"
with pytest.raises(KeyError, match=msg):
grps.get_group(("a2", "b1"))

0 comments on commit 6cd6069

Please sign in to comment.