-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: .reset_index() should raise with an invalid level name (GH20925) #21016
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
Changes from 11 commits
ef542b1
837d4da
a10f6ac
30bc393
cfd70af
6b87a3a
50c553e
1ecf7c3
2945890
284d016
a413bc9
f08ea70
03226f7
d0c7ebc
1df935f
71d23a1
c9afed3
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 |
---|---|---|
|
@@ -768,3 +768,24 @@ def test_head_tail(test_data): | |
assert_series_equal(test_data.series.head(0), test_data.series[0:0]) | ||
assert_series_equal(test_data.series.tail(), test_data.series[-5:]) | ||
assert_series_equal(test_data.series.tail(0), test_data.series[0:0]) | ||
|
||
|
||
def test_reset_index_drop_errmsg(): | ||
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.
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. renamed def as |
||
# https://github.com/pandas-dev/pandas/issues/20925 | ||
|
||
# Check KeyError raised for series index where passed level name is missing | ||
s = pd.Series(range(4)) | ||
with tm.assert_raises_regex(KeyError, 'must be same as name'): | ||
s.reset_index('wrong', drop=True) | ||
with tm.assert_raises_regex(KeyError, 'must be same as name'): | ||
s.reset_index('wrong') | ||
|
||
# Check KeyError raised for series where 'level' to be dropped is missing | ||
s = pd.Series(range(4), index=pd.MultiIndex.from_product([[1, 2]] * 2)) | ||
with tm.assert_raises_regex(KeyError, 'not found'): | ||
s.reset_index('wrong', drop=True) | ||
|
||
# Check that .reset_index([],drop=True) doesn't fail | ||
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. This is fine but probably not in the right test: could you append it to 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. Have moved it to function |
||
result = pd.Series(range(4)).reset_index([], drop=True) | ||
expected = pd.Series(range(4)) | ||
assert_series_equal(result, expected) |
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 just noticed this is in the wrong file...
reset_index
is tested inpandas/tests/series/test_alter_axes.py
, nottest_indexing.py
.While you're at it, please replace
# https://github.com/pandas-dev/pandas/issues/20925
with the standard# GH 20925
.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.
Thanks didn't know that the right file was
test_alter_axes.py
Have moved the function there (now renamed as
test_reset_index_drop_errors
based on @TomAugspurger 's comment) - also updated comment for # GH 20925