Skip to content

Commit b526058

Browse files
add test_groupby_aggregation_empty_group
1 parent 219bc5e commit b526058

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

+11
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,17 @@ def test_missing_raises(self):
881881
match = re.escape("Column(s) ['C'] do not exist")
882882
with pytest.raises(KeyError, match=match):
883883
df.groupby("A").agg(c=("C", "sum"))
884+
885+
def test_groupby_aggregation_empty_group():
886+
# https://github.com/pandas-dev/pandas/issues/18869
887+
def f(x):
888+
if len(x) == 0:
889+
sys.exit(1)
890+
return len(x)
891+
892+
df = DataFrame({"A": pd.Categorical(['a', 'a'], categories=['a', 'b', 'c']), "B": [1, 1]})
893+
with pytest.raises(SystemExit):
894+
df.groupby('A').agg(f)
884895

885896
def test_agg_namedtuple(self):
886897
df = DataFrame({"A": [0, 1], "B": [1, 2]})

0 commit comments

Comments
 (0)