From 0e96f37d441045ceef91695a424da67e3d13466c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 31 Mar 2020 17:00:08 -0700 Subject: [PATCH 1/2] rename --> test_setitem --- .../frame/{test_mutate_columns.py => indexing/test_setitem.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pandas/tests/frame/{test_mutate_columns.py => indexing/test_setitem.py} (100%) diff --git a/pandas/tests/frame/test_mutate_columns.py b/pandas/tests/frame/indexing/test_setitem.py similarity index 100% rename from pandas/tests/frame/test_mutate_columns.py rename to pandas/tests/frame/indexing/test_setitem.py From bab331de2206320a9bf3ac593152cf351391bbc3 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 31 Mar 2020 17:54:52 -0700 Subject: [PATCH 2/2] CLN: construct more directly --- pandas/tests/frame/indexing/test_setitem.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index e3f2a67c2f469..c12643f413490 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas import DataFrame, Series +from pandas import DataFrame, Index, Series import pandas._testing as tm # Column add, remove, delete. @@ -12,14 +12,17 @@ def test_setitem_error_msmgs(self): # GH 7432 df = DataFrame( - {"foo": ["a", "b", "c"], "bar": [1, 2, 3], "baz": ["d", "e", "f"]} - ).set_index("foo") - s = DataFrame( - {"foo": ["a", "b", "c", "a"], "fiz": ["g", "h", "i", "j"]} - ).set_index("foo") + {"bar": [1, 2, 3], "baz": ["d", "e", "f"]}, + index=Index(["a", "b", "c"], name="foo"), + ) + ser = Series( + ["g", "h", "i", "j"], + index=Index(["a", "b", "c", "a"], name="foo"), + name="fiz", + ) msg = "cannot reindex from a duplicate axis" with pytest.raises(ValueError, match=msg): - df["newcol"] = s + df["newcol"] = ser # GH 4107, more descriptive error message df = DataFrame(np.random.randint(0, 2, (4, 4)), columns=["a", "b", "c", "d"])