-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Lambda function returns KeyError in DataFrameGroupBy.agg #27921
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: Lambda function returns KeyError in DataFrameGroupBy.agg #27921
Conversation
pandas/core/groupby/generic.py
Outdated
| order : List[Tuple[str, str]] | ||
| Pairs of the input and output column names. | ||
| order : List[int] | ||
| List of reordered index of columns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List of columns indices
TomAugspurger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is growing to be pretty complex. I wonder: is it possible to pass order into maybe_mangle_lamdas? Then when we iterate over elements of func we might update the corresponding name in order?
|
emm, not sure, could take a look, but probably will change few functions as well. This looks indeed a bit complex, but I found out there are quite few issues around it:
|
|
Hello @charlesdong1991! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-08-26 18:03:11 UTC |
|
Hi, @TomAugspurger I simplified the code quite a lot, but still in |
TomAugspurger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, thanks.
TomAugspurger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a few unit tests that directly test _uniquify_aggfunc?
pandas/core/groupby/generic.py
Outdated
| return aggspec, columns, order | ||
|
|
||
| # uniquify aggfunc name if duplicated in order list | ||
| uniquified_order = _uniquify_aggfunc(order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you verify that the output example in the docstring still passes?
Can you also add a docstring example were this new code is hit in https://github.com/pandas-dev/pandas/pull/27921/files#diff-bfee1ba9e7cb79839776fac1a57ed940R1742?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, verified. And added tests for _make_unique function, all tests pass locally @TomAugspurger
|
wanna give a follow-up review? @TomAugspurger |
|
Thanks! |
black pandasgit diff upstream/master -u -- "*.py" | flake8 --diff