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
def typer_with_random_arg(x, random_arg):
print(type(x))
def typer_no_args(x):
print(type(x))
a = pd.DataFrame({'A': [1,4], 'B':[5,10]}, index=['A', 'B'])
a.groupby('A').agg(typer_with_random_arg,random_arg=True)
a.groupby('A').agg(typer_no_args)
Issue Description
Hi!
While building a custom aggregation function to use with pandas.core.groupby.DataFrameGroupBy.aggregate, I noticed a really weird behaviour: the .aggregate() function provides an *arg parameter to provide args to the grouping function, but this, which shouldn't really change what's passed to the function, actually does: when the function has no arguments, it receives a pd.Series (which is unexpected, as according to the docs, if a function, must either work when passed a DataFrame or when passed to DataFrame.apply.), while if you add an argument it behaves as expected and gets a DataFrame.
Expected Behavior
The aggregating function gets a pd.DataFrame regardless of having passed args or not.
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
Hi! While building a custom aggregation function to use with
pandas.core.groupby.DataFrameGroupBy.aggregate
, I noticed a really weird behaviour: the.aggregate()
function provides an*arg
parameter to provide args to the grouping function, but this, which shouldn't really change what's passed to the function, actually does: when the function has no arguments, it receives a pd.Series (which is unexpected, as according to the docs, if a function, must either work when passed a DataFrame or when passed to DataFrame.apply.), while if you add an argument it behaves as expected and gets a DataFrame.Expected Behavior
The aggregating function gets a
pd.DataFrame
regardless of having passed args or not.Installed Versions