Skip to content

Commit

Permalink
Test .groupby() encodes NaNs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolker-KU committed Dec 10, 2023
1 parent 9b51ab2 commit 238cba5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pandas/tests/groupby/test_indexing.py
Expand Up @@ -331,3 +331,15 @@ def test_groupby_get_nonexisting_groups():
msg = "('a2', 'b1')"
with pytest.raises(KeyError, match=msg):
grps.get_group(("a2", "b1"))


def test_groupby_multiindex_nan_encoding():
# GH#54347
df = pd.DataFrame(
{"A": [1, 2, 3, 4], "B": [1, float("nan"), 2, float("nan")], "C": [2, 4, 6, 8]}
)

df_grouped = df.groupby(["A", "B"], dropna=False).sum()

index = df_grouped.index
tm.assert_index_equal(index, pd.MultiIndex.from_frame(index.to_frame()))

0 comments on commit 238cba5

Please sign in to comment.