@@ -274,46 +274,34 @@ def _make_index(
274
274
self , data , alldata , columns , indexnamerow : list [Scalar ] | None = None
275
275
) -> tuple [Index | None , Sequence [Hashable ] | MultiIndex ]:
276
276
index : Index | None
277
- if not is_index_col (self .index_col ) or not self .index_col :
278
- index = None
277
+ if isinstance (self .index_col , list ) and len (self .index_col ):
278
+ to_remove = []
279
+ index = []
280
+ for idx in self .index_col :
281
+ if isinstance (idx , str ):
282
+ raise ValueError (f"Index { idx } invalid" )
283
+ to_remove .append (idx )
284
+ index .append (alldata [idx ])
285
+ # remove index items from content and columns, don't pop in
286
+ # loop
287
+ for i in sorted (to_remove , reverse = True ):
288
+ alldata .pop (i )
289
+ if not self ._implicit_index :
290
+ columns .pop (i )
291
+ index = self ._agg_index (index )
292
+
293
+ # add names for the index
294
+ if indexnamerow :
295
+ coffset = len (indexnamerow ) - len (columns )
296
+ index = index .set_names (indexnamerow [:coffset ])
279
297
else :
280
- simple_index = self ._get_simple_index (alldata , columns )
281
- index = self ._agg_index (simple_index )
282
-
283
- # add names for the index
284
- if indexnamerow :
285
- coffset = len (indexnamerow ) - len (columns )
286
- assert index is not None
287
- index = index .set_names (indexnamerow [:coffset ])
298
+ index = None
288
299
289
300
# maybe create a mi on the columns
290
301
columns = self ._maybe_make_multi_index_columns (columns , self .col_names )
291
302
292
303
return index , columns
293
304
294
- @final
295
- def _get_simple_index (self , data , columns ):
296
- def ix (col ):
297
- if not isinstance (col , str ):
298
- return col
299
- raise ValueError (f"Index { col } invalid" )
300
-
301
- to_remove = []
302
- index = []
303
- for idx in self .index_col :
304
- i = ix (idx )
305
- to_remove .append (i )
306
- index .append (data [i ])
307
-
308
- # remove index items from content and columns, don't pop in
309
- # loop
310
- for i in sorted (to_remove , reverse = True ):
311
- data .pop (i )
312
- if not self ._implicit_index :
313
- columns .pop (i )
314
-
315
- return index
316
-
317
305
@final
318
306
def _clean_mapping (self , mapping ):
319
307
"""converts col numbers to names"""
0 commit comments