Skip to content

Commit

Permalink
adjust for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Jul 6, 2019
1 parent ab2fdf5 commit 3a19d89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __new__(
result._set_levels(levels, copy=copy, validate=False)
result._set_codes(codes, copy=copy, validate=False)

result._names = [None for _ in levels]
result._names = [None] * len(levels)
if names is not None:
# handles name validation
result._set_names(names)
Expand Down
20 changes: 7 additions & 13 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,10 @@ def get_new_values(self):
def get_new_columns(self):
if self.value_columns is None:
if self.lift == 0:
lev = self.removed_level._shallow_copy()
lev.name = self.removed_name
return lev
return self.removed_level._shallow_copy(name=self.removed_name)

lev = self.removed_level.insert(0, item=self.removed_level._na_value)
lev.name = self.removed_name
return lev
return lev.rename(self.removed_name)

stride = len(self.removed_level) + self.lift
width = len(self.value_columns)
Expand Down Expand Up @@ -302,12 +299,10 @@ def get_new_index(self):

# construct the new index
if len(self.new_index_levels) == 1:
lev, lab = self.new_index_levels[0], result_codes[0]
if (lab == -1).any():
lev = lev.insert(len(lev), lev._na_value)
new_index = lev.take(lab)
new_index.name = self.new_index_names[0]
return new_index
level, level_codes = self.new_index_levels[0], result_codes[0]
if (level_codes == -1).any():
level = level.insert(len(level), level._na_value)
return level.take(level_codes).rename(self.new_index_names[0])

return MultiIndex(
levels=self.new_index_levels,
Expand Down Expand Up @@ -663,8 +658,7 @@ def _convert_level_number(level_num, columns):
new_names = this.columns.names[:-1]
new_columns = MultiIndex.from_tuples(unique_groups, names=new_names)
else:
new_columns = this.columns.levels[0]._shallow_copy()
new_columns.name = this.columns.names[0]
new_columns = this.columns.levels[0]._shallow_copy(name=this.columns.names[0])
unique_groups = new_columns

# time to ravel the values
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ def test_reset_index(self, float_frame):
values = lev.take(level_codes)
name = names[i]
tm.assert_index_equal(values, Index(deleveled[name]), check_names=False)
assert values.name is None

stacked.index.names = [None, None]
deleveled2 = stacked.reset_index()
Expand Down

0 comments on commit 3a19d89

Please sign in to comment.