Skip to content

BUG: Should not raise errors in .set_names for MultiIndex with nlevels == 1 (GH21149) #21196

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 10 commits into from
May 29, 2018
Prev Previous commit
Next Next commit
Update test_multi.py
  • Loading branch information
KalyanGokhale authored May 25, 2018
commit 6f65c994a444254a1477db16c393d2b1c9fcceb1
18 changes: 11 additions & 7 deletions pandas/tests/indexes/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,20 @@ def test_set_name_methods(self):
assert res is None
assert ind.names == new_names2

def test_multiindex_set_names(self):
@pytest.mark.parametrize('inplace_flg,expected_out', [
(True, pd.MultiIndex(levels=[[0, 1]],
labels=[[0, 1]],
names=['first'])),
(False, pd.MultiIndex(levels=[[0, 1]],
labels=[[0, 1]]))])
def test_multiindex_set_names(self, inplace_flg, expected_out):
# GH 21149
'''Ensure that .set_names for MultiIndex with
""" Ensure that .set_names for MultiIndex with
nlevels == 1 does not raise any errors
'''
"""
result = pd.MultiIndex.from_product([[0, 1]])
result.set_names('first', level=0, inplace=True)
expected = pd.MultiIndex(levels=[[0, 1]],
labels=[[0, 1]],
names=['first'])
result.set_names('first', level=0, inplace=inplace_flg)
expected = expected_out
tm.assert_index_equal(result, expected)

def test_set_levels_labels_directly(self):
Expand Down