BUG: SeriesGroupBy works with any column name specified in NamedAgg · Issue #34422 · pandas-dev/pandas (original) (raw)
- 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.
DisallowingNamedAgg
and tuples withSeriesGroupBy
.
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