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

FIX: Allow aggregate to return dictionaries again #16741 #16752

Merged
merged 5 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Performance Improvements
Bug Fixes
~~~~~~~~~

- Fixes regression in 0.20, `aggregate` allows dictionaries as return values again (:issue:`16741`)
Copy link
Contributor

Choose a reason for hiding this comment

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

be a little more verbose here. say :func:Series.aggregate and :func:DataFrame.aggregate


Conversion
^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/reduce.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ cdef class SeriesGrouper:
cdef inline _extract_result(object res):
""" extract the result object, it might be a 0-dim ndarray
or a len-1 0-dim, or a scalar """
if hasattr(res, 'values'):
if hasattr(res, 'values') and isinstance(res.values, np.ndarray):
res = res.values
if not np.isscalar(res):
if isinstance(res, np.ndarray):
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/groupby/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ def test_cython_agg_frame_columns(self):
df.groupby(level=0, axis='columns').mean()
df.groupby(level=0, axis='columns').mean()

def test_cython_agg_return_dict(self):
ts = self.df.groupby('A')['B'].agg(
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 here

lambda x: x.value_counts().to_dict())
assert isinstance(ts.loc['foo'], dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

construct the expected frame and use assert_frame_equal


def test_cython_fail_agg(self):
dr = bdate_range('1/1/2000', periods=50)
ts = Series(['A', 'B', 'C', 'D', 'E'] * 10, index=dr)
Expand Down