We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
import pandas as pd data = { "Product": ["apple", "pear", "banana"], "Sales": [100, 150, 200], "Price": [1, 1.5, 2], } df = pd.DataFrame(data) def func1(x): # x is Series y = x.sum() return y def func2(x): # x is a single value y = 0 return y agg_funcs = { "Sales": func1, "Price": func2 } df_column_spec_agg = df.agg(agg_funcs) print(df_column_spec_agg)
in func1() x is Series, but in func2() x is a single value.
func1()
func2()
and with an error:
ValueError: cannot perform both aggregation and transformation operations simultaneously
type(x) should be same in func1() and func2()
type(x)
Python 3.12.8 (main, Dec 11 2024, 08:52:29) [GCC 13.3.0] on linux
commit : 0691c5c python : 3.12.8 python-bits : 64 OS : Linux OS-release : 6.4.0-150600.23.30-default Version : #1 SMP PREEMPT_DYNAMIC Sat Dec 7 08:37:53 UTC 2024 (8c25a0a) machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 2.2.3 numpy : 2.2.0 pytz : 2024.2 dateutil : 2.9.0.post0 pip : 24.3.1 Cython : None sphinx : None IPython : 8.30.0 adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 blosc : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None html5lib : None hypothesis : None gcsfs : None jinja2 : 3.1.4 lxml.etree : None matplotlib : 3.9.3 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None psycopg2 : None pymysql : None pyarrow : None pyreadstat : None pytest : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.14.1 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlsxwriter : None zstandard : None tzdata : 2024.2 qtpy : None pyqt5 : None
The text was updated successfully, but these errors were encountered:
Thanks for the report! Confirmed on 2.2.x, but this is fixed on main. The OP gives the output:
Sales 450 Price 0 dtype: int64
Closing.
Sorry, something went wrong.
No branches or pull requests
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
Issue Description
in
func1()
x is Series, but infunc2()
x is a single value.and with an error:
Expected Behavior
type(x)
should be same infunc1()
andfunc2()
Installed Versions
Python 3.12.8 (main, Dec 11 2024, 08:52:29) [GCC 13.3.0] on linux
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.8
python-bits : 64
OS : Linux
OS-release : 6.4.0-150600.23.30-default
Version : #1 SMP PREEMPT_DYNAMIC Sat Dec 7 08:37:53 UTC 2024 (8c25a0a)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.3
numpy : 2.2.0
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : None
sphinx : None
IPython : 8.30.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : 3.9.3
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: