8000 BUG: fixed issue with mixed type groupby aggregate by nreeve17 · Pull Request #17003 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: fixed issue with mixed type groupby aggregate #17003

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

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
used safe_sort in groupby.py
  • Loading branch information
Nicolai Reeve committed Aug 4, 2017
commit 34ca8d891b0b4cb23623aaff8a9b20ebe1925e9d
8 changes: 2 additions & 6 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from pandas.io.formats.printing import pprint_thing
from pandas.util._validators import validate_kwargs

from pandas.core.sorting import safe_sort
import pandas.core.algorithms as algorithms
import pandas.core.common as com
from pandas.core.config import option_context
Expand Down Expand Up @@ -2883,12 +2884,7 @@ def aggregate(self, func_or_funcs, *args, **kwargs):
except Exception:
result = self._aggregate_named(func_or_funcs, *args, **kwargs)

# mixed types fail to sort
try:
values = sorted(result)
except TypeError:
values = result
index = Index(values, name=self.grouper.names[0])
index = Index(safe_sort(result), name=self.grouper.names[0])
ret = Series(result, index=index)

if not self.as_index: # pragma: no cover
Expand Down
0