Skip to content

Can't use same function twice with named aggregation #28426

New issue

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

Closed
dmitriyshashkin opened this issue Sep 13, 2019 · 2 comments · Fixed by #28428
Closed

Can't use same function twice with named aggregation #28426

dmitriyshashkin opened this issue Sep 13, 2019 · 2 comments · Fixed by #28428

Comments

@dmitriyshashkin
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd
from functools import partial

quant50 = partial(np.percentile, q=50)
quant70 = partial(np.percentile, q=70)

test = pd.DataFrame({'col1': ['a', 'a', 'b', 'b', 'b'], 'col2': [1,2,3,4,5]})

test.groupby('col1').agg(
    quantile_50=('col2', quant50),
    quantile_70=('col2', quant70)
)

Problem description

I'm trying to calculate multiple percentiles, I get the following error: "Function names must be unique, found multiple named percentile"

It's an old problem #7186 but I assumed that it should've been solved with the named aggregations. Now there is no need to deduce the column name from the function name, the column name was specified explicitly.

Expected Output

column | quantile_50 | quantile_70
a | 1.5 | 2
b | 4.0 | 3

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.1.11-200.fc29.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.1
numpy : 1.16.4
pytz : 2017.3
dateutil : 2.7.2
pip : 19.1.1
setuptools : 39.1.0
Cython : 0.28.1
pytest : 3.3.1
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.0
xlsxwriter : None
lxml.etree : 4.3.3
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 6.3.1
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.3.3
matplotlib : 2.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.9.0
pytables : None
s3fs : None
scipy : 1.2.1
sqlalchemy : 1.1.18
tables : None
xarray : None
xlrd : 1.1.0
xlwt : None
xlsxwriter : None

@TomAugspurger
Copy link
Contributor

Hmm... we mangle the name of lambdas to allow this type of thing. Should that be applied to all input functions, since the names aren't used in the output?

@charlesdong1991
Copy link
Member

yes, with mangled lambdas being allowed, this error could be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants