Skip to content

BUG: Fix droped result column in groupby with as_index False #33247

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

Conversation

phofl
Copy link
Member

@phofl phofl commented Apr 2, 2020

The aggregate function lost the results of the aggregate operation, if the as_index=False flag was set and one of the result columns is relabeled. The index was reset at first, adding columns to the DataFrame. The relabeling operation only took the columns before resetting the index as input. So the weird error occurred. I changed the order of the index reset and the relabeling. This fixes the issue.

@mroeschke
Copy link
Member

One comment otherwise LGTM

@phofl
Copy link
Member Author

phofl commented Apr 3, 2020

Done @mroeschke

@phofl
Copy link
Member Author

phofl commented Apr 3, 2020

Merge conflict in whats new.

@phofl phofl requested a review from jreback April 19, 2020 21:07
@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Apr 19, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good a couple of comments

@phofl phofl requested a review from jreback April 19, 2020 22:00
@phofl phofl requested a review from mroeschke May 23, 2020 20:00
@mroeschke
Copy link
Member

Looks good. Looks like there are some failing code checks

@phofl
Copy link
Member Author

phofl commented May 25, 2020

Looks good. Looks like there are some failing code checks

Missed that one, is green now.

@jreback
Copy link
Contributor

jreback commented May 26, 2020

let's rebase this on top of #34012 (or could wait, likey to merge that one tomorrow). this migth be fine but will want to re-look.

@phofl
Copy link
Member Author

phofl commented May 27, 2020

@jreback Merged master after the other pull request was merged. Seems to be fine.

phofl added 2 commits June 14, 2020 20:03
� Conflicts:
�	doc/source/whatsnew/v1.1.0.rst
�	pandas/tests/groupby/aggregate/test_aggregate.py
@phofl
Copy link
Member Author

phofl commented Jun 14, 2020

@jreback merged master

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some doc comments, looks good otherwise.

@jreback jreback added this to the 1.1 milestone Jun 14, 2020
@phofl
Copy link
Member Author

phofl commented Jun 15, 2020

@jreback Changed the docs, test failure seems unrelated

@jreback
Copy link
Contributor

jreback commented Jun 15, 2020

looks good, can you rebase to fix the conflict (the other fail is ok), ping when ready.

@phofl
Copy link
Member Author

phofl commented Jun 15, 2020

@jreback fixed conflict, failure unrelated. Can be merged

@jreback
Copy link
Contributor

jreback commented Jul 9, 2020

can you merge master and ping when green

@jreback
Copy link
Contributor

jreback commented Jul 14, 2020

@phofl if you can merge master will have another look

@phofl
Copy link
Member Author

phofl commented Jul 14, 2020

Sorry, was a Bit busy the last few days. Will merge master tomorrow and ping when ready

@jreback jreback merged commit 653f091 into pandas-dev:master Jul 15, 2020
@jreback
Copy link
Contributor

jreback commented Jul 15, 2020

thanks @phofl

fangchenli pushed a commit to fangchenli/pandas that referenced this pull request Jul 16, 2020
@phofl phofl deleted the 32240_groupby_as_index_false_loses_results_when_relabeling branch September 5, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NamedAgg with as_index= False drops aggregated values
3 participants