Skip to content

ERR: Improve error message for Series.loc.getitem with too many dimensions #39372

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
Jan 28, 2021

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 24, 2021

tuple in tuple means we are indexing index and columns

@phofl phofl added Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves labels Jan 24, 2021
@jreback jreback added this to the 1.3 milestone Jan 24, 2021
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.

lgtm. can you also test setitem. if its not trivial, can do in a separate PR/issue.

@phofl
Copy link
Member Author

phofl commented Jan 24, 2021

Good point. This is pretty straight forward

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.

lgtm can you merge master and ping on green

@jreback jreback merged commit 71f40a6 into pandas-dev:master Jan 28, 2021
@jreback
Copy link
Contributor

jreback commented Jan 28, 2021

thanks @phofl

@phofl phofl deleted the 35349 branch January 28, 2021 08:36
@jbrockmendel
Copy link
Member

jbrockmendel commented Jun 30, 2021

@phofl I think this introduces a problem if the MultiIndex has a level that includes tuples e.g. (xref #27591)

lev1 = ["a", "b", "c"]
lev2 = [(0, 1), (1, 0)]
lev3 = [0, 1]
cols = pd.MultiIndex.from_product([lev1, lev2, lev3], names=["x", "y", "z"])
df = pd.DataFrame(index=range(5), columns=cols)
[test for DataFrame behavior (also broken xref #27591)

ser = df.iloc[0]
result2 = ser.loc[lev1[0], lev2[0], lev3[0]]  # <-- raises incorrectly
expected2 = ser.iloc[:1]  # actually i think this should drop all the levels and return a scalar, but thats a whole other thing
tm.assert_series_equal(result2, expected2)

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-intuitive behavior when multi-indexing a Series
3 participants