diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index b5b13d6b10511..974ef3ecee336 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2970,3 +2970,16 @@ def test_groupby_numeric_only_std_no_result(numeric_only): ValueError, match="could not convert string to float: 'bar'" ): dfgb.std(numeric_only=numeric_only) + + +@pytest.mark.parametrize("bug_var", [1, "a"]) +def test_groupby_sum_on_nan_should_return_nan(bug_var): + # GH 24196 + df = pd.DataFrame({ + 'A': [bug_var, bug_var, bug_var, np.nan] + }) + dfgb = df.groupby(lambda x: x) + result = dfgb.sum(min_count=1) + + expected_df = DataFrame([bug_var, bug_var, bug_var, np.nan], columns=["A"]) + tm.assert_frame_equal(result, expected_df)