Skip to content

BUG: raise when wrong level name is passed to "unstack" #27631

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

Merged
merged 1 commit into from
Jul 29, 2019

Conversation

toobaz
Copy link
Member

@toobaz toobaz commented Jul 28, 2019

Notice that I profited to make the error message a bit more understandable.

@toobaz toobaz force-pushed the unstack_wrong_label_18303 branch from dccd0b3 to 20add9f Compare July 29, 2019 14:13
@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #27631 into master will decrease coverage by 50.6%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #27631       +/-   ##
===========================================
- Coverage   93.02%   42.41%   -50.61%     
===========================================
  Files         182      182               
  Lines       50257    50259        +2     
===========================================
- Hits        46750    21316    -25434     
- Misses       3507    28943    +25436
Flag Coverage Δ
#multiple ?
#single 42.41% <0%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/core/reshape/reshape.py 13.2% <0%> (-86.37%) ⬇️
pandas/core/indexes/base.py 55.21% <0%> (-42.17%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/io/gcs.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/s3.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.38%) ⬇️
... and 138 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 61362be...3a4a241. Read the comment docs.

@pep8speaks
Copy link

pep8speaks commented Jul 29, 2019

Hello @toobaz! 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-07-29 14:42:07 UTC

@toobaz toobaz force-pushed the unstack_wrong_label_18303 branch from 20add9f to 3a4a241 Compare July 29, 2019 14:22
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

LGTM. Just a comment on the whatsnew.

@@ -128,7 +128,7 @@ Groupby/resample/rolling
Reshaping
^^^^^^^^^

-
- A ``KeyError`` is now raised if ``.unstack()`` is called on a flat :class:`Index` passing a name which is not the correct one (:issue:`18303`)
Copy link
Contributor

Choose a reason for hiding this comment

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

"is called on a Series or DataFrame with a flat".

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems this affects both stack & unstack?

Copy link
Member Author

Choose a reason for hiding this comment

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

"is called on a Series or DataFrame with a flat".

Fixed, thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems this affects both stack & unstack?

I added tests for both, but stack was already raising the error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood, thanks.

@toobaz toobaz force-pushed the unstack_wrong_label_18303 branch from 3a4a241 to 40d19a0 Compare July 29, 2019 14:41
@jreback jreback added Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jul 29, 2019
@jreback jreback added this to the 0.25.1 milestone Jul 29, 2019
@jreback jreback added Error Reporting Incorrect or improved errors from pandas and removed Bug labels Jul 29, 2019
@jreback jreback merged commit 0fd888c into pandas-dev:master Jul 29, 2019
@jreback
Copy link
Contributor

jreback commented Jul 29, 2019

thanks @toobaz

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Jul 29, 2019
@toobaz toobaz deleted the unstack_wrong_label_18303 branch August 3, 2019 11:44
quintusdias pushed a commit to quintusdias/pandas_dev that referenced this pull request Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.unstack(label) accepts wrong labels if index is flat
4 participants