Skip to content

CLN: clarify TypeError for IndexSlice argument to pd.xs #35411

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 10 commits into from
Aug 7, 2020

Conversation

arw2019
Copy link
Member

@arw2019 arw2019 commented Jul 25, 2020

As per discussion in #35301 we do not support IndexSlice arguments to xs. This PR aims to clarify the TypeError thrown when that happens.

I created a separate issue to house the discussion re: functionality of loc vs xs (#35418).

@arw2019 arw2019 force-pushed the xs-fails-with-slice branch from 8f947ad to 71a63bd Compare July 27, 2020 18:24
@simonjayhawkins simonjayhawkins added the Error Reporting Incorrect or improved errors from pandas label Jul 31, 2020
try:
loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
except TypeError:
raise TypeError(f"Expected label or tuple of labels, got {key}")
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 from e (need to add the the except as well)

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.

if you can move the test; merge master and ping on green.

@@ -1280,6 +1280,26 @@ def test_level_with_tuples(self):
tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(result2, expected)

def test_xs_with_IndexSlice(self):
# GH 35301
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 move to: pandas/tests/indexing/multiindex/test_xs.py

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Aug 6, 2020
@jreback jreback added this to the 1.2 milestone Aug 6, 2020
@arw2019 arw2019 force-pushed the xs-fails-with-slice branch from 90d0f8b to a2e51bc Compare August 7, 2020 00:57
@arw2019 arw2019 force-pushed the xs-fails-with-slice branch from a2e51bc to 9ed2654 Compare August 7, 2020 01:00
@jreback jreback merged commit 9843926 into pandas-dev:master Aug 7, 2020
@jreback
Copy link
Contributor

jreback commented Aug 7, 2020

thanks @arw2019 very nice (failure is unrelated)

@arw2019
Copy link
Member Author

arw2019 commented Aug 7, 2020

great! thanks @jreback for reviewing

@arw2019 arw2019 deleted the xs-fails-with-slice branch August 7, 2020 17:19
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 Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: xs not working with slice
3 participants