-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Bug in xs ignored droplevel #37776
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9e5e81
[BUG]: DataFrame.xs ignored droplevel for columns
phofl 3205e8d
Move whatsnew
phofl 6614f5e
Fix typo
phofl f3d54f7
Add test
phofl 5c5eee1
Refactor code
phofl 0f0bb77
Modify if else condition
phofl c0ac9b2
Merge branch 'master' of https://github.com/pandas-dev/pandas into 19056
phofl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3708,18 +3708,21 @@ class animal locomotion | |
return result | ||
|
||
if axis == 1: | ||
return self[key] | ||
if drop_level: | ||
return self[key] | ||
index = self.columns | ||
else: | ||
index = self.index | ||
|
||
index = self.index | ||
if isinstance(index, MultiIndex): | ||
try: | ||
loc, new_index = self.index._get_loc_level( | ||
loc, new_index = index._get_loc_level( | ||
key, level=0, drop_level=drop_level | ||
) | ||
except TypeError as e: | ||
raise TypeError(f"Expected label or tuple of labels, got {key}") from e | ||
else: | ||
loc = self.index.get_loc(key) | ||
loc = index.get_loc(key) | ||
|
||
if isinstance(loc, np.ndarray): | ||
if loc.dtype == np.bool_: | ||
|
@@ -3729,9 +3732,9 @@ class animal locomotion | |
return self._take_with_is_copy(loc, axis=axis) | ||
|
||
if not is_scalar(loc): | ||
new_index = self.index[loc] | ||
new_index = index[loc] | ||
|
||
if is_scalar(loc): | ||
if is_scalar(loc) and axis == 0: | ||
# In this case loc should be an integer | ||
if self.ndim == 1: | ||
# if we encounter an array-like and we only have 1 dim | ||
|
@@ -3747,7 +3750,10 @@ class animal locomotion | |
name=self.index[loc], | ||
dtype=new_values.dtype, | ||
) | ||
|
||
elif is_scalar(loc): | ||
result = self.iloc[:, [loc]] | ||
elif axis == 1: | ||
result = self.iloc[:, loc] | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make this part of the higher level if/else There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
result = self.iloc[loc] | ||
result.index = new_index | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 viewThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#37832