Skip to content

BUG: raise KeyError if MultiIndex.get_loc_level is asked unused label #22230

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 3 commits into from
Aug 9, 2018

Conversation

toobaz
Copy link
Member

@toobaz toobaz commented Aug 7, 2018

@codecov
Copy link

codecov bot commented Aug 7, 2018

Codecov Report

Merging #22230 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #22230      +/-   ##
==========================================
+ Coverage   92.07%   92.07%   +<.01%     
==========================================
  Files         169      169              
  Lines       50683    50684       +1     
==========================================
+ Hits        46666    46668       +2     
+ Misses       4017     4016       -1
Flag Coverage Δ
#multiple 90.48% <100%> (ø) ⬆️
#single 42.34% <10%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/multi.py 95.33% <100%> (+0.08%) ⬆️

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 d52748c...31b55c4. Read the comment docs.

@toobaz toobaz requested a review from WillAyd August 7, 2018 12:37
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.

small comments

@@ -271,6 +271,10 @@ def test_get_loc_level():
assert new_index is None

pytest.raises(KeyError, index.get_loc_level, (2, 2))
# GH 22221: unused label
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add the issue number here

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean repeat it below?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is good as written


if level > 0 or self.lexsort_depth == 0:
# Desired level is not sorted
locs = np.array(labels == code, dtype=bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can pass copy=False here

Copy link
Contributor

Choose a reason for hiding this comment

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

can you do this

@jreback
Copy link
Contributor

jreback commented Aug 7, 2018

can you also add the original OP test somewhere.

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.

minor comment


if level > 0 or self.lexsort_depth == 0:
# Desired level is not sorted
locs = np.array(labels == code, dtype=bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you do this

@@ -271,6 +271,10 @@ def test_get_loc_level():
assert new_index is None

pytest.raises(KeyError, index.get_loc_level, (2, 2))
# GH 22221: unused label
Copy link
Contributor

Choose a reason for hiding this comment

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

this is good as written

@jreback jreback added this to the 0.24.0 milestone Aug 8, 2018
@jreback jreback added the Bug label Aug 8, 2018
@toobaz toobaz force-pushed the mi_get_loc_level_unused_22221 branch from ea539d8 to 31b55c4 Compare August 8, 2018 12:16
@jreback jreback merged commit fb6116f into pandas-dev:master Aug 9, 2018
@jreback
Copy link
Contributor

jreback commented Aug 9, 2018

thanks @toobaz

@toobaz toobaz deleted the mi_get_loc_level_unused_22221 branch August 9, 2018 05:43
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
…pandas-dev#22230)

* BUG: raise KeyError if MultiIndex.get_loc_level is asked unused label

closes pandas-dev#22221

* TST: test groupby.apply() with user-defined function returning an empty chunk

* CLN: remove named lambda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mi.drop(x).get_loc_level(x) returns empty slice (rather than raising KeyError)
2 participants