Skip to content

Commit 3a6469d

Browse files
committed
Review (jreback)
1 parent 46f8dc7 commit 3a6469d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

pandas/core/frame.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
is_sequence,
6161
is_named_tuple)
6262
from pandas.core.dtypes.concat import _get_sliced_frame_result_type
63-
from pandas.core.dtypes.generic import (ABCSeries, ABCIndexClass,
64-
ABCMultiIndex, ABCDataFrame)
63+
from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass, ABCMultiIndex
6564
from pandas.core.dtypes.missing import isna, notna
6665

6766

@@ -3955,16 +3954,17 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
39553954
keys = [keys]
39563955

39573956
missing = []
3958-
for x in keys:
3959-
if (is_scalar(x) or isinstance(x, tuple)) and x in self:
3957+
for col in keys:
3958+
if (is_scalar(col) or isinstance(col, tuple)) and col in self:
3959+
# tuples can be both column keys or list-likes
3960+
# if they are valid column keys, everything is fine
39603961
continue
3961-
elif is_scalar(x) and x not in self:
3962-
# a tuple gets tried as column key first;
3963-
# otherwise considered as a list-like; i.e. not missing
3964-
missing.append(x)
3965-
elif (not is_list_like(x) or isinstance(x, set)
3966-
or isinstance(x, ABCDataFrame)
3967-
or (isinstance(x, np.ndarray) and x.ndim > 1)):
3962+
elif is_scalar(col) and col not in self:
3963+
# tuples that are not column keys are considered list-like,
3964+
# not considered missing
3965+
missing.append(col)
3966+
elif (not is_list_like(col) or isinstance(col, set)
3967+
or getattr(col, 'ndim', 1) > 1):
39683968
raise TypeError('The parameter "keys" may only contain a '
39693969
'combination of valid column keys and '
39703970
'one-dimensional list-likes')

0 commit comments

Comments
 (0)