-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: wrong output index mapping of results when groupby both scan and reduction aggregation are passed #40695
Comments
Thanks for the report!
Do you have something in mind here? In pandas, A possible alternative, which I think you may want here, is to treat both operations as transformers. You can do this today, but it has to be as two separate ops joined together by
I think |
With #35725 giving users the option to make all arguments reduce (agg), I would propose to make this issue about transform accepting list-like and dict-like arguments. In this way, users can opt for either alignment (reduce or transform) as they desire. |
Output mapping for transform looks better. Broadcasts for reducers. Also, |
Thanks @karthikeyann for the response, I've updated the OP. This looks doable similar to the way |
Another option would be to always align the result. In this way, a filter would then leave null values in the result. If the index is completely mismatched, the result would then be a column of all null values. |
Whichever option all users prefer, is good. I don't have any preference as long as it does not allow wrong mapping in the output. |
Edit (#40695 (comment)): This issue is about
groupby(...).transform
not accepting list-likes or dict-likes.Code Sample, a copy-pastable example
Problem description
When both scan aggregrations (cumsum, cummin, cummax, cumcount) and any of reduction aggregartions (sum, min, max, prod, ...), are passed to
groupby.agg
, output value mapping to index in the result is wrong.scan aggregations produce index as RangeIndex (0 to N-1).
reduction aggregations usually map to grouped keys. In the given example, it maps to values of keys in resulting index.
Expected Output
Common method to align the output should be decided and implemented.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.7.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-137-generic
Version : #141-Ubuntu SMP Fri Feb 19 13:46:27 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.2.3
numpy : 1.19.2
pytz : 2020.4
dateutil : 2.8.1
pip : 21.0.1
setuptools : 49.6.0.post20201009
Cython : 0.29.22
pytest : 6.2.2
hypothesis : 6.8.1
sphinx : 3.5.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.21.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 0.8.7
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.52.0
The text was updated successfully, but these errors were encountered: