diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 667656cb4de02..58c5e5155e4e8 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2840,3 +2840,14 @@ def test_groupby_index_name_in_index_content(val_in, index, val_out): result = series.to_frame().groupby("blah").sum() expected = expected.to_frame() tm.assert_frame_equal(result, expected) + + +def test_groupby_on_column_drops_na(): + # GH 21755 + df = DataFrame( + {"a": [np.nan, "foo", "bar", np.nan, np.nan, "baz"], "b": [0, 1, 2, 3, 4, 5]} + ) + result = df.groupby("a").head(1) + expected = DataFrame({"a": ["foo", "bar", "baz"], "b": [1, 2, 5]}, index=[1, 2, 5]) + + tm.assert_frame_equal(result, expected)