Skip to content

Commit e38e450

Browse files
author
Marco Gorelli
committed
🎨 handle empty in , make whatsnewentry public-facing
1 parent ab685fd commit e38e450

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pandas/core/groupby/generic.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def _aggregate_multiple_funcs(self, arg):
311311

312312
arg = zip(columns, arg)
313313

314-
results = {}
314+
results: Mapping[base.OutputKey, Union[Series, DataFrame]] = {}
315315
for idx, (name, func) in enumerate(arg):
316316
obj = self
317317

@@ -326,10 +326,7 @@ def _aggregate_multiple_funcs(self, arg):
326326
if any(isinstance(x, DataFrame) for x in results.values()):
327327
# let higher level handle
328328
return {key.label: value for key, value in results.items()}
329-
330-
if results:
331-
return DataFrame(self._wrap_aggregated_output(results), columns=columns)
332-
return DataFrame(columns=columns)
329+
return DataFrame(self._wrap_aggregated_output(results), columns=columns)
333330

334331
def _wrap_series_output(
335332
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]], index: Index
@@ -360,8 +357,10 @@ def _wrap_series_output(
360357
if len(output) > 1:
361358
result = DataFrame(indexed_output, index=index)
362359
result.columns = columns
363-
else:
360+
elif not columns.empty:
364361
result = Series(indexed_output[0], index=index, name=columns[0])
362+
else:
363+
result = DataFrame()
365364

366365
return result
367366

0 commit comments

Comments
 (0)