Skip to content
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

BUG: Bug in xs ignored droplevel #37776

Merged
merged 7 commits into from
Nov 13, 2020
Merged

BUG: Bug in xs ignored droplevel #37776

merged 7 commits into from
Nov 13, 2020

Conversation

phofl
Copy link
Member

@phofl phofl commented Nov 11, 2020

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Nov 11, 2020
return self[key]
if drop_level:
return self[key]
return self[[key]]
Copy link
Member

Choose a reason for hiding this comment

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

PITA but this causes us to make a copy instead of a view. can we re-use any of the code in the rest of the method to keep this consistent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would make this pretty complex probably, but will have a look tomorrow

Copy link
Member Author

Choose a reason for hiding this comment

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

This should work, but got a bit more complex. Using iloc now to select the data if droplevel=False

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, some comments, ping on green.

@@ -3749,8 +3752,13 @@ class animal locomotion
)

else:
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 make this part of the higher level if/else

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

result.index = new_index
else:
result = (
self.iloc[:, loc] if not is_scalar(loc) else self.iloc[:, [loc]]
Copy link
Contributor

Choose a reason for hiding this comment

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

worth making is_scalar another case in the eliif (I think it will read simpler that way)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, reads better, thx.

@jreback jreback added this to the 1.2 milestone Nov 13, 2020
@jreback jreback merged commit 5c111cb into pandas-dev:master Nov 13, 2020
@jreback
Copy link
Contributor

jreback commented Nov 13, 2020

thanks @phofl

@phofl phofl deleted the 19056 branch November 13, 2020 13:15
@@ -3747,7 +3750,10 @@ class animal locomotion
name=self.index[loc],
dtype=new_values.dtype,
)

elif is_scalar(loc):
result = self.iloc[:, [loc]]
Copy link
Member

Choose a reason for hiding this comment

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

Until we implement #36195, this returns a copy and not a view. In followup can you make this self.iloc[:, slice(loc, loc + 1)], probably need to test that we're getting a view

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

DataFrame.xs("key", axis=1, drop_level=False) still dropping level
3 participants