You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Issue Description
I couldn't find an open issue that was the exact same as this. But it seems that `groupby(…).agg` with a user defined function seems to change the object passed into the function depending on the presence of keyword arguments.
In the example above, I am taking the same `Groupby` object and passing a udf into the `.agg` method. As highlighted by the documentation, I would expect each group to be passed as a `DataFrame`. However what is unexpected is that:
1. In the first sample output, we can see each grouped `Series` is into the UDF.
2. In the second sample output where I pass a keyword argument to the UDF, it seems that the entire `DataFrame` is passed into the udf.
### Expected Behavior
I would expect that the presence of keyword arguments would not change the input type of the passed objects to a `Groupby.agg`. Moreover, according to [DataFrame.GroupBy.aggregate](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.aggregate.html) udf's should operate on `DataFrame`s and not individual `Series`.
Expected output (created by swapping `.agg` for `.apply`):
```python
--- no kwargs passed to ufunc
<class 'pandas.core.frame.DataFrame'>
group value1 value2
0 a 0 11
1 a 1 12
2 a 2 13
3 a 3 14
4 a 4 15
<class 'pandas.core.frame.DataFrame'>
group value1 value2
5 b 5 16
6 b 6 17
7 b 7 18
8 b 8 19
9 b 9 20
--- passing kwarg to ufunc
<class 'pandas.core.frame.DataFrame'>
group value1 value2
0 a 0 11
1 a 1 12
2 a 2 13
3 a 3 14
4 a 4 15
<class 'pandas.core.frame.DataFrame'>
group value1 value2
5 b 5 16
6 b 6 17
7 b 7 18
8 b 8 19
9 b 9 20
Installed Versions
Version : #1 SMP Fri, 22 Jul 2022 23:29:06 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
Pandas version checks
I have checked that this issue has not already been reported.
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
Installed Versions
Version : #1 SMP Fri, 22 Jul 2022 23:29:06 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.3
numpy : 1.21.5
pytz : 2021.3
dateutil : 2.8.2
setuptools : 58.1.0
pip : 21.2.4
Cython : None
pytest : 7.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.0.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.5.0
gcsfs : None
markupsafe : 2.0.1
matplotlib : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 8.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
snappy : None
sqlalchemy : 1.4.32
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: