@@ -4166,37 +4166,31 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
4166
4166
names = []
4167
4167
if append :
4168
4168
names = [x for x in self .index .names ]
4169
- if isinstance (self .index , MultiIndex ):
4169
+ if isinstance (self .index , ABCMultiIndex ):
4170
4170
for i in range (self .index .nlevels ):
4171
4171
arrays .append (self .index ._get_level_values (i ))
4172
4172
else :
4173
4173
arrays .append (self .index )
4174
4174
4175
4175
to_remove = []
4176
4176
for col in keys :
4177
- if isinstance (col , MultiIndex ):
4178
- # append all but the last column so we don't have to modify
4179
- # the end of this loop
4180
- for n in range (col .nlevels - 1 ):
4177
+ if isinstance (col , ABCMultiIndex ):
4178
+ for n in range (col .nlevels ):
4181
4179
arrays .append (col ._get_level_values (n ))
4182
-
4183
- level = col ._get_level_values (col .nlevels - 1 )
4184
4180
names .extend (col .names )
4185
- elif isinstance (col , Series ):
4186
- level = col ._values
4187
- names .append (col .name )
4188
- elif isinstance (col , Index ):
4189
- level = col
4181
+ elif isinstance (col , (ABCIndexClass , ABCSeries )):
4182
+ # if Index then not MultiIndex (treated above)
4183
+ arrays .append (col )
4190
4184
names .append (col .name )
4191
- elif isinstance (col , (list , np .ndarray , Index )):
4192
- level = col
4185
+ elif isinstance (col , (list , np .ndarray )):
4186
+ arrays . append ( col )
4193
4187
names .append (None )
4188
+ # from here, col can only be a column label
4194
4189
else :
4195
- level = frame [col ]._values
4190
+ arrays . append ( frame [col ]._values )
4196
4191
names .append (col )
4197
4192
if drop :
4198
4193
to_remove .append (col )
4199
- arrays .append (level )
4200
4194
4201
4195
index = ensure_index_from_sequences (arrays , names )
4202
4196
0 commit comments