@@ -1472,33 +1472,34 @@ def set_index(self, labels, append=False, inplace=False, verify_integrity=False)
1472
1472
labels = [labels ]
1473
1473
1474
1474
err_msg = (
1475
- 'The parameter "labels" may be an Index or a list-like '
1476
- "and it must be of the same length is the calling Series."
1475
+ 'The parameter "labels" may be a column key, one-dimensional '
1476
+ "array, or a list containing only "
1477
+ "one-dimensional arrays."
1477
1478
)
1478
1479
1479
- if isinstance (
1480
- labels , (ABCIndexClass , ABCSeries , np .ndarray , list , abc .Iterator )
1481
- ):
1482
- # arrays are fine as long as they are one-dimensional
1483
- # iterators get converted to list below
1484
- if getattr (labels , "ndim" , 1 ) != 1 :
1485
- raise ValueError (err_msg )
1480
+ for col in labels :
1481
+ if isinstance (
1482
+ col , (ABCIndexClass , ABCSeries , np .ndarray , list , abc .Iterator )
1483
+ ):
1484
+ # arrays are fine as long as they are one-dimensional
1485
+ # iterators get converted to list below
1486
+ if getattr (col , "ndim" , 1 ) != 1 :
1487
+ raise ValueError (err_msg )
1486
1488
1487
1489
if inplace :
1488
1490
ser = self
1489
1491
else :
1490
1492
ser = self .copy ()
1491
1493
1492
1494
arrays = []
1495
+ names = []
1493
1496
if append :
1494
1497
names = [x for x in self .index .names ]
1495
1498
if isinstance (self .index , ABCMultiIndex ):
1496
1499
for i in range (self .index .nlevels ):
1497
1500
arrays .append (self .index ._get_level_values (i ))
1498
1501
else :
1499
1502
arrays .append (self .index )
1500
- else :
1501
- names = []
1502
1503
1503
1504
for col in labels :
1504
1505
if isinstance (col , ABCMultiIndex ):
@@ -1509,18 +1510,18 @@ def set_index(self, labels, append=False, inplace=False, verify_integrity=False)
1509
1510
# if Index then not MultiIndex (treated above)
1510
1511
arrays .append (col )
1511
1512
names .append (col .name )
1512
- elif isinstance (col , (np .ndarray , )):
1513
+ elif isinstance (col , (list , np .ndarray )):
1513
1514
arrays .append (col )
1514
1515
names .append (None )
1515
1516
elif isinstance (col , abc .Iterator ):
1516
1517
arrays .append (list (col ))
1517
1518
names .append (None )
1519
+ # from here, col can only be a column label
1518
1520
else :
1519
- msg = "Passing type '{typ}' in labels is not allowed"
1520
- raise ValueError (msg .format (typ = type (col )))
1521
+ raise ValueError ("MultiIndex Levels must be array-like" )
1521
1522
1522
1523
if len (arrays [- 1 ]) != len (self ):
1523
- # check newest element against length of calling series , since
1524
+ # check newest element against length of calling ser , since
1524
1525
# ensure_index_from_sequences would not raise for append=False.
1525
1526
raise ValueError (
1526
1527
"Length mismatch: Expected {len_self} rows, "
0 commit comments