Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: add test to verify if SystemExit is raised correctly. #56145

Merged
merged 14 commits into from
Nov 29, 2023
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)
Loading