Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [4, 5]}, index=pd.Index(list("AB"), name="group"))
def _agg_func(*args, **kwargs):
for arg in args:
print("ARG:\n")
print(arg)
print()
return None
# _agg_func will receive a pandas Series of column "a", then after it, column "b"
df.groupby(level="group").agg(_agg_func)
# _agg_func will receive a DataFrame with columns "a" and "b" for each group
df.groupby(level="group").agg(_agg_func, some_kwarg="abc")
Issue Description
When performing an aggregation over groups, my colleagues and I observed that DataFrameGroupBy.agg has inconsistent behavior when the function passed to the agg method has or not keyword arguments.
If agg receives the function _agg_func without keyword arguments, then the input to _agg_func will be a pandas.Series. If keyword arguments are passed, then the input to _agg_func is a pandas.DataFrame.
Expected Behavior
As per the docs, the parameter func should be able to receive a pandas.DataFrame as input, hence, I would expect that the input for _agg_func should always be a pandas.DataFrame, independently if the function receives or not a keyword argument.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
When performing an aggregation over groups, my colleagues and I observed that
DataFrameGroupBy.agg
has inconsistent behavior when the function passed to theagg
method has or not keyword arguments.If
agg
receives the function_agg_func
without keyword arguments, then the input to_agg_func
will be apandas.Series
. If keyword arguments are passed, then the input to_agg_func
is apandas.DataFrame
.Expected Behavior
As per the docs, the parameter
func
should be able to receive apandas.DataFrame
as input, hence, I would expect that the input for_agg_func
should always be apandas.DataFrame
, independently if the function receives or not a keyword argument.Installed Versions