-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: Add DataFrame.droplevel #21871
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
API: Add DataFrame.droplevel #21871
Changes from all commits
b46d46f
8836d3f
7862326
c43d261
95336db
5f9c648
808bc16
dbc25da
2333f7c
6b8f22b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,6 +1056,28 @@ def test_reindex_signature(self): | |
"limit", "copy", "level", "method", | ||
"fill_value", "tolerance"} | ||
|
||
def test_droplevel(self): | ||
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. add the issue number as a comment |
||
# GH20342 | ||
df = pd.DataFrame([ | ||
[1, 2, 3, 4], | ||
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 add tests for series as well 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. I did, on lines 1085-1089 :) 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. oh not in THIS test. pls separate out and put in tests/series/test_alter_axes |
||
[5, 6, 7, 8], | ||
[9, 10, 11, 12] | ||
]) | ||
df = df.set_index([0, 1]).rename_axis(['a', 'b']) | ||
df.columns = pd.MultiIndex.from_tuples([('c', 'e'), ('d', 'f')], | ||
names=['level_1', 'level_2']) | ||
|
||
# test that dropping of a level in index works | ||
expected = df.reset_index('a', drop=True) | ||
result = df.droplevel('a', axis='index') | ||
assert_frame_equal(result, expected) | ||
|
||
# test that dropping of a level in columns works | ||
expected = df.copy() | ||
expected.columns = pd.Index(['c', 'd'], name='level_1') | ||
result = df.droplevel('level_2', axis='columns') | ||
assert_frame_equal(result, expected) | ||
|
||
|
||
class TestIntervalIndex(object): | ||
|
||
|
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.
anyone think we should add
inplace
to make this consistent, with other axis ops (e.g. reset_index / set_index)?cc @TomAugspurger
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.
makes sense to me to expose
inplace
!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.
I'd say leave it out for now, unless someone asks for it.
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.
okay, will do!