MCPcopy
hub / github.com/pandas-dev/pandas / _groupby_and_aggregate

Method _groupby_and_aggregate

pandas/core/resample.py:532–573  ·  view source on GitHub ↗

Re-evaluate the obj with a groupby aggregation.

(self, how, *args, **kwargs)

Source from the content-addressed store, hash-verified

530 return grouped
531
532 def _groupby_and_aggregate(self, how, *args, **kwargs):
533 """
534 Re-evaluate the obj with a groupby aggregation.
535 """
536 grouper = self._grouper
537
538 # Excludes `on` column when provided
539 obj = self._obj_with_exclusions
540
541 grouped = get_groupby(obj, by=None, grouper=grouper, group_keys=self.group_keys)
542
543 try:
544 if callable(how):
545 # TODO: test_resample_apply_with_additional_args fails if we go
546 # through the non-lambda path, not clear that it should.
547 func = lambda x: how(x, *args, **kwargs)
548 result = grouped.aggregate(func)
549 else:
550 result = grouped.aggregate(how, *args, **kwargs)
551 except (AttributeError, KeyError):
552 # we have a non-reducing function; try to evaluate
553 # alternatively we want to evaluate only a column of the input
554
555 # test_apply_to_one_column_of_df the function being applied references
556 # a DataFrame column, but aggregate_item_by_item operates column-wise
557 # on Series, raising AttributeError or KeyError
558 # (depending on whether the column lookup uses getattr/__getitem__)
559 result = grouped.apply(how, *args, **kwargs)
560
561 except ValueError as err:
562 if "Must produce aggregated value" in str(err):
563 # raised in _aggregate_named
564 # see test_apply_without_aggregation, test_apply_with_mutated_index
565 pass
566 else:
567 raise
568
569 # we have a non-reducing function
570 # try to evaluate
571 result = grouped.apply(how, *args, **kwargs)
572
573 return self._wrap_result(result)
574
575 @final
576 def _get_resampler_for_grouping(

Callers 2

aggregateMethod · 0.95
_downsampleMethod · 0.80

Calls 4

_wrap_resultMethod · 0.95
get_groupbyFunction · 0.90
aggregateMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected