Skip to content
18 changes: 18 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2873,3 +2873,21 @@ def test_obj_with_exclusions_duplicate_columns():
result = gb._obj_with_exclusions
expected = df.take([0, 2, 3], axis=1)
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("numeric_only", [True, False])
def test_groupby_numeric_only_std_no_result(numeric_only):
# GH 51080
dicts_non_numeric = [{"a": "foo", "b": "bar"}, {"a": "car", "b": "dar"}]
df = DataFrame(dicts_non_numeric)
dfgb = df.groupby("a", as_index=False, sort=False)

if numeric_only:
result = dfgb.std(numeric_only=True)
expected_df = DataFrame(["foo", "car"], columns=["a"])
tm.assert_frame_equal(result, expected_df)
else:
with pytest.raises(
ValueError, match="could not convert string to float: 'bar'"
):
dfgb.std(numeric_only=numeric_only)