Skip to content

Commit 6a90b79

Browse files
committed
Moved fixes into '_groupby_and_aggregate'.
1 parent f90d3e7 commit 6a90b79

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

pandas/core/resample.py

+15-25
Original file line numberDiff line numberDiff line change
@@ -387,42 +387,32 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
387387

388388
obj = self._selected_obj
389389

390+
result = None
390391
try:
391392
grouped = groupby(obj, by=None, grouper=grouper, axis=self.axis)
392393
except TypeError:
393394

394395
# panel grouper
395396
grouped = PanelGroupBy(obj, grouper=grouper, axis=self.axis)
397+
result = grouped.aggregate(how, *args, **kwargs)
396398

397-
try:
398-
result = self._try_aggregate(grouped, how, *args, **kwargs)
399-
except Exception:
400-
401-
# we have a non-reducing function
402-
# try to evaluate
403-
result = grouped.apply(how, *args, **kwargs)
399+
if result is None:
400+
try:
401+
if compat.callable(how):
402+
# Check if the function is reducing or not.
403+
result = grouped._aggregate_item_by_item(how,
404+
*args, **kwargs)
405+
else:
406+
result = grouped.aggregate(how, *args, **kwargs)
407+
except Exception:
408+
409+
# we have a non-reducing function
410+
# try to evaluate
411+
result = grouped.apply(how, *args, **kwargs)
404412

405413
result = self._apply_loffset(result)
406414
return self._wrap_result(result)
407415

408-
def _try_aggregate(self, grouped, how, *args, **kwargs):
409-
"""
410-
Tries to aggregate a 'grouped' object.
411-
When 'how' param is a callable, we aggregate item by item
412-
to check if the function is reducing or not.
413-
414-
Parameters
415-
----------
416-
grouped : GroupBy object
417-
how : string / cython mapped function
418-
"""
419-
if not compat.callable(how) or isinstance(grouped, PanelGroupBy):
420-
return grouped.aggregate(how, *args, **kwargs)
421-
422-
# Callables might change the count of columns (GH #15169)
423-
result = grouped._aggregate_item_by_item(how, *args, **kwargs)
424-
return result
425-
426416
def _apply_loffset(self, result):
427417
"""
428418
if loffset is set, offset the result index

0 commit comments

Comments
 (0)