Skip to content

Commit 15fc11f

Browse files
committed
Revert new warnings
1 parent 9121d49 commit 15fc11f

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
@@ -3862,29 +3862,10 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
38623862
-------
38633863
dataframe : DataFrame
38643864
"""
3865-
from pandas import Series
3866-
3865+
inplace = validate_bool_kwarg(inplace, 'inplace')
38673866
if not isinstance(keys, list):
38683867
keys = [keys]
38693868

3870-
# collect elements from "keys" that are not allowed array types
3871-
col_labels = [x for x in keys
3872-
if not isinstance(x, (Series, Index, MultiIndex,
3873-
list, np.ndarray))]
3874-
if any(x not in self for x in col_labels):
3875-
# if there are any labels that are invalid, we raise a KeyError
3876-
missing = [x for x in col_labels if x not in self]
3877-
raise KeyError('{}'.format(missing))
3878-
3879-
elif len(set(col_labels)) < len(col_labels):
3880-
# if all are valid labels, but there are duplicates
3881-
dup = Series(col_labels)
3882-
dup = list(dup.loc[dup.duplicated()])
3883-
raise ValueError('Passed duplicate column names '
3884-
'to keys: {dup}'.format(dup=dup))
3885-
3886-
inplace = validate_bool_kwarg(inplace, 'inplace')
3887-
38883869
if inplace:
38893870
frame = self
38903871
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)