Skip to content
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Plotting
Groupby/Resample/Rolling
^^^^^^^^^^^^^^^^^^^^^^^^

-
- Bug in :method:'agg' when pqssing a list in the method agg on a Groupby with attibute as_index set as False, returned a DataFrame with the Groupby key as an index, now return the Groupby key as a column.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this much simpler, I am not sure what you are fixing here. add the issue number

-
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def is_any_frame():
# we require a list, but not an 'str'
return self._aggregate_multiple_funcs(arg,
_level=_level,
_axis=_axis), None
_axis=_axis), True
else:
result = None

Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,23 @@ def test_multi_function_flexible_mix(df):
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = grouped.aggregate(d)
tm.assert_frame_equal(result, expected)


def test_not_as_index_agg_list():

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the issue number. parameterize on as_index=[True,False]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like

@pytest.mark.parametize('as_index', [True, False]); def test_agg_with_as_index(as_index): .... 
array = [[3, 1, 2],
[3, 3, 4],
[4, 5, 6],
[4, 7, 8]]
df = pd.DataFrame(array, columns=['shouldnt_be_index', 'A', 'B'])
groupby = df.groupby('shouldnt_be_index', as_index=False)
result = groupby.agg(['min', 'max'])

array2 = [[3, 1, 3, 2, 4],
[4, 5, 7, 6, 8]]
columns = pd.MultiIndex(levels=[['A', 'B', 'shouldnt_be_index'],
['min', 'max', '']],
codes=[[2, 0, 0, 1, 1], [2, 0, 1, 0, 1]])
expected = pd.DataFrame(array2, columns=columns)

tm.assert_frame_equal(result, expected)