Skip to content

Commit

Permalink
🎨 handle empty in , make whatsnewentry public-facing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Gorelli committed Jan 21, 2020
1 parent 932aac5 commit 33c57a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ Groupby/resample/rolling
- Bug in :meth:`DataFrame.groupby` when using nunique on axis=1 (:issue:`30253`)
- Bug in :meth:`GroupBy.quantile` with multiple list-like q value and integer column names (:issue:`30289`)
- Bug in :meth:`GroupBy.pct_change` and :meth:`core.groupby.SeriesGroupBy.pct_change` causes ``TypeError`` when ``fill_method`` is ``None`` (:issue:`30463`)
- Bug in :meth:`SeriesGroupBy._aggregate_multiple_funcs` was resulting in aggregations being overwritten when they shared the same name (:issue:`30092`)
- Bug in :meth:`SeriesGroupBy.aggregate` was resulting in aggregations being overwritten when they shared the same name (:issue:`30092`)

Reshaping
^^^^^^^^^
Expand Down
11 changes: 5 additions & 6 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _aggregate_multiple_funcs(self, arg):

arg = zip(columns, arg)

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

Expand All @@ -326,10 +326,7 @@ def _aggregate_multiple_funcs(self, arg):
if any(isinstance(x, DataFrame) for x in results.values()):
# let higher level handle
return {key.label: value for key, value in results.items()}

if results:
return DataFrame(self._wrap_aggregated_output(results), columns=columns)
return DataFrame(columns=columns)
return DataFrame(self._wrap_aggregated_output(results), columns=columns)

def _wrap_series_output(
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]], index: Index
Expand Down Expand Up @@ -360,8 +357,10 @@ def _wrap_series_output(
if len(output) > 1:
result = DataFrame(indexed_output, index=index)
result.columns = columns
else:
elif not columns.empty:
result = Series(indexed_output[0], index=index, name=columns[0])
else:
result = DataFrame()

return result

Expand Down

0 comments on commit 33c57a2

Please sign in to comment.