Skip to content

BUG: SeriesGroupBy works with any column name specified in NamedAgg #34422

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
3 tasks done
gurukiran07 opened this issue May 28, 2020 · 2 comments · Fixed by #34435
Closed
3 tasks done

BUG: SeriesGroupBy works with any column name specified in NamedAgg #34422

gurukiran07 opened this issue May 28, 2020 · 2 comments · Fixed by #34435
Assignees
Milestone

Comments

@gurukiran07
Copy link
Contributor

gurukiran07 commented May 28, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

s = pd.Series([1,1,2,2,3,3,4,5])

s.groupby(s.values).agg(one = pd.NamedAgg(column='anything',aggfunc='sum'))
   one
1    2
2    4
3    6
4    4
5    5

s.groupby(s.values).agg(one=('something','sum'))

   one
1    2
2    4
3    6
4    4
5    5

Problem description

For SeriesGroupBy.agg named aggregation, it accepts any column name as mentioned in the above examples but Series doesn't have any columns.

Expected Output

After discussing with @TomAugspurger and @MarcoGorelli in another issue #34380 regarding this issue in the comments, We came to a solution that

So for SeriesGroupBy.agg, if there are any tuples or NamedAgg present in kwargs then I think we should raise.
Disallowing NamedAgg and tuples with SeriesGroupBy.

s.groupby(s.values).agg(one = pd.NamedAgg(column='anything',aggfunc='sum'))
# Error should be raised.
s.groupby(s.values).agg(one=('something','sum'))
# Error should be raised.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.3
numpy : 1.18.3
pytz : 2019.3
dateutil : 2.8.1
pip : 20.1.1
setuptools : 46.1.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None

@gurukiran07 gurukiran07 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 28, 2020
@MarcoGorelli
Copy link
Member

Thanks - if you like to work on this, please comment 'take' so the issue is assigned to you

@gurukiran07
Copy link
Contributor Author

take

@jreback jreback added Groupby and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 1, 2020
@jreback jreback added this to the 1.1 milestone Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants