Skip to content

Commit 15a73c0

Browse files
committed
fr
1 parent d178aec commit 15a73c0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pandas/core/frame.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -3888,25 +3888,25 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
38883888
3 2013 7 84
38893889
4 2014 10 31
38903890
"""
3891-
from pandas import Series
3892-
38933891
if not isinstance(keys, list):
38943892
keys = [keys]
38953893

3896-
# collect elements from "keys" that are not allowed array types
3897-
col_labels = [x for x in keys
3898-
if not isinstance(x, (Series, Index, MultiIndex,
3899-
list, np.ndarray))]
3900-
if any(x not in self for x in col_labels):
3901-
# if there are any labels that are invalid, we raise a KeyError
3902-
missing = [x for x in col_labels if x not in self]
3894+
missing = []
3895+
for x in keys:
3896+
if not (is_scalar(x) or isinstance(x, tuple)):
3897+
if not isinstance(x, (ABCSeries, ABCIndexClass, ABCMultiIndex,
3898+
list, np.ndarray)):
3899+
raise TypeError('keys may only contain a combination of '
3900+
'the following: valid column keys, '
3901+
'Series, Index, MultiIndex, list or '
3902+
'np.ndarray')
3903+
else:
3904+
if x not in self:
3905+
missing.append(x)
3906+
3907+
if missing:
39033908
raise KeyError('{}'.format(missing))
3904-
elif len(set(col_labels)) < len(col_labels):
3905-
# if all are valid labels, but there are duplicates
3906-
dup = Series(col_labels)
3907-
dup = list(dup.loc[dup.duplicated()])
3908-
raise ValueError('Passed duplicate column names '
3909-
'to keys: {dup}'.format(dup=dup))
3909+
39103910
vi = verify_integrity
39113911
return super(DataFrame, self).set_index(keys=keys, drop=drop,
39123912
append=append, inplace=inplace,

0 commit comments

Comments
 (0)