Skip to content

Commit

Permalink
TST: groupby.agg calls func with empty groups (#56145)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaruguchiKazuto authored Nov 29, 2023
1 parent 7012d6a commit e8f0598
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,3 +1651,18 @@ def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation():
gb = df.groupby("grps")
result = gb.agg(td=("td", "cumsum"))
tm.assert_frame_equal(result, expected)


def test_groupby_aggregation_empty_group():
# https://github.com/pandas-dev/pandas/issues/18869
def func(x):
if len(x) == 0:
raise ValueError("length must not be 0")
return len(x)

df = DataFrame(
{"A": pd.Categorical(["a", "a"], categories=["a", "b", "c"]), "B": [1, 1]}
)
msg = "length must not be 0"
with pytest.raises(ValueError, match=msg):
df.groupby("A", observed=False).agg(func)

0 comments on commit e8f0598

Please sign in to comment.