Skip to content

Commit

Permalink
TST: Test groupby for columns with string objects (#52757)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaiwald authored Apr 22, 2023
1 parent 84f3591 commit 681af4c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2970,3 +2970,14 @@ 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 = 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)

0 comments on commit 681af4c

Please sign in to comment.