Skip to content

Commit 2430273

Browse files
committed
Revert new warnings
1 parent bcaab67 commit 2430273

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

pandas/core/frame.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -3888,29 +3888,10 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
38883888
-------
38893889
dataframe : DataFrame
38903890
"""
3891-
from pandas import Series
3892-
3891+
inplace = validate_bool_kwarg(inplace, 'inplace')
38933892
if not isinstance(keys, list):
38943893
keys = [keys]
38953894

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]
3903-
raise KeyError('{}'.format(missing))
3904-
3905-
elif len(set(col_labels)) < len(col_labels):
3906-
# if all are valid labels, but there are duplicates
3907-
dup = Series(col_labels)
3908-
dup = list(dup.loc[dup.duplicated()])
3909-
raise ValueError('Passed duplicate column names '
3910-
'to keys: {dup}'.format(dup=dup))
3911-
3912-
inplace = validate_bool_kwarg(inplace, 'inplace')
3913-
39143895
if inplace:
39153896
frame = self
39163897
else:

pandas/tests/frame/test_alter_axes.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ def test_set_index_pass_arrays_duplicate(self, frame_of_index_cols, drop,
185185
keys = [box1(df['A']), box2(df['A'])]
186186

187187
# == gives ambiguous Boolean for Series
188-
if keys[0] is 'A' and keys[1] is 'A':
189-
with tm.assert_raises_regex(ValueError,
190-
'Passed duplicate column names.*'):
188+
if drop and keys[0] is 'A' and keys[1] is 'A':
189+
with tm.assert_raises_regex(KeyError, '.*'):
191190
df.set_index(keys, drop=drop, append=append)
192191
else:
193192
result = df.set_index(keys, drop=drop, append=append)
@@ -225,15 +224,17 @@ def test_set_index_verify_integrity(self, frame_of_index_cols):
225224
'Index has duplicate keys'):
226225
df.set_index([df['A'], df['A']], verify_integrity=True)
227226

228-
def test_set_index_raise(self, frame_of_index_cols):
227+
@pytest.mark.parametrize('append', [True, False])
228+
@pytest.mark.parametrize('drop', [True, False])
229+
def test_set_index_raise(self, frame_of_index_cols, drop, append):
229230
df = frame_of_index_cols
230231

231232
with tm.assert_raises_regex(KeyError, '.*'): # column names are A-E
232-
df.set_index(['foo', 'bar', 'baz'], verify_integrity=True)
233+
df.set_index(['foo', 'bar', 'baz'], drop=drop, append=append)
233234

234235
# non-existent key in list with arrays
235236
with tm.assert_raises_regex(KeyError, '.*'):
236-
df.set_index([df['A'], df['B'], 'X'], verify_integrity=True)
237+
df.set_index([df['A'], df['B'], 'X'], drop=drop, append=append)
237238

238239
def test_construction_with_categorical_index(self):
239240
ci = tm.makeCategoricalIndex(10)

0 commit comments

Comments
 (0)