Skip to content

Commit e8f0598

Browse files
TST: groupby.agg calls func with empty groups (#56145)
1 parent 7012d6a commit e8f0598

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

+15
Original file line numberDiff line numberDiff line change
@@ -1651,3 +1651,18 @@ def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation():
16511651
gb = df.groupby("grps")
16521652
result = gb.agg(td=("td", "cumsum"))
16531653
tm.assert_frame_equal(result, expected)
1654+
1655+
1656+
def test_groupby_aggregation_empty_group():
1657+
# https://github.com/pandas-dev/pandas/issues/18869
1658+
def func(x):
1659+
if len(x) == 0:
1660+
raise ValueError("length must not be 0")
1661+
return len(x)
1662+
1663+
df = DataFrame(
1664+
{"A": pd.Categorical(["a", "a"], categories=["a", "b", "c"]), "B": [1, 1]}
1665+
)
1666+
msg = "length must not be 0"
1667+
with pytest.raises(ValueError, match=msg):
1668+
df.groupby("A", observed=False).agg(func)

0 commit comments

Comments
 (0)