Skip to content

Commit 056edfa

Browse files
authored
TST: groupby.std with no numeric columns and numeric_only=True (#51761)
1 parent d07931f commit 056edfa

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/groupby/test_groupby.py

+18
Original file line numberDiff line numberDiff line change
@@ -2873,3 +2873,21 @@ def test_obj_with_exclusions_duplicate_columns():
28732873
result = gb._obj_with_exclusions
28742874
expected = df.take([0, 2, 3], axis=1)
28752875
tm.assert_frame_equal(result, expected)
2876+
2877+
2878+
@pytest.mark.parametrize("numeric_only", [True, False])
2879+
def test_groupby_numeric_only_std_no_result(numeric_only):
2880+
# GH 51080
2881+
dicts_non_numeric = [{"a": "foo", "b": "bar"}, {"a": "car", "b": "dar"}]
2882+
df = DataFrame(dicts_non_numeric)
2883+
dfgb = df.groupby("a", as_index=False, sort=False)
2884+
2885+
if numeric_only:
2886+
result = dfgb.std(numeric_only=True)
2887+
expected_df = DataFrame(["foo", "car"], columns=["a"])
2888+
tm.assert_frame_equal(result, expected_df)
2889+
else:
2890+
with pytest.raises(
2891+
ValueError, match="could not convert string to float: 'bar'"
2892+
):
2893+
dfgb.std(numeric_only=numeric_only)

0 commit comments

Comments
 (0)