Skip to content

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

Merged
merged 17 commits into from
May 18, 2018
Merged
Prev Previous commit
Next Next commit
GH20925
Made edits to test file for labels and introduced blank spaces between test cases.
  • Loading branch information
KalyanGokhale committed May 13, 2018
commit 6b87a3a5e44e4e945d9c2cc1bd0b108985a4b31c
9 changes: 4 additions & 5 deletions pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,16 +772,15 @@ def test_head_tail(test_data):

def test_reset_index_drop_errmsg():
Copy link
Member

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 in pandas/tests/series/test_alter_axes.py, not test_indexing.py.

While you're at it, please replace # https://github.com/pandas-dev/pandas/issues/20925 with the standard # GH 20925.

Copy link
Contributor Author

@KalyanGokhale KalyanGokhale May 17, 2018

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

Copy link
Contributor

Choose a reason for hiding this comment

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

errmsg -> errors or error_message

Copy link
Contributor Author

@KalyanGokhale KalyanGokhale May 17, 2018

Choose a reason for hiding this comment

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

done. renamed def as test_reset_index_drop_errors

# https://github.com/pandas-dev/pandas/issues/20925
# Data for Test Case 1 and 2

# Checks that KeyError is raised for series where no 'level' name is defined
s = pd.Series(range(4))
# Test Case 1
with tm.assert_raises_regex(KeyError, 'must be same as name'):
s.reset_index('wrong', drop=True)
# Test Case 2
with tm.assert_raises_regex(KeyError, 'must be same as name'):
s.reset_index('wrong')
# Data for Test Case 3

# Checks that KeyError is raised for series where 'level' to be dropped is not is defined levels
s = pd.Series(range(4), index=pd.MultiIndex.from_product([[1, 2]] * 2))
# Test Case 3
with tm.assert_raises_regex(KeyError, 'not found'):
s.reset_index('wrong', drop=True)