In groupby, agg may take various paths. While some branching may be necessary, this can lead to inconsistent results and should be avoided if possible. The following methods take different paths to do the main part of the computation. This issue is to investigate these methods and reduce branching if possible.

Once the deprecation in #7155 is enforced, the apply method does not branch in this fashion. A similar issue for transform is #42907.

DataFrameGroupBy.agg

  • _python_agg_general
  • _aggregate_frame
  • DataFrameGroupBy.agg with func wrapped as a list

DataFrameGroupBy._python_agg_general

  • _ptyhon_apply_general
  • BaseGrouper.agg_series

cc @topper-123

Comment From: topper-123

I agree that this too complex currently and Pandas as project would benefit a lot from getting this simplified.

I haven't looked into the these methods lately so haven't any clear image of how much it possible to simplify this/cut down on paths without breaking backward compatibility, but I do think we need to look seriously into how to simplify these.