1
1
import numpy as np
2
2
import pytest
3
3
4
- from pandas import DataFrame , Series
4
+ from pandas import DataFrame , Index , Series
5
5
import pandas ._testing as tm
6
6
7
7
# Column add, remove, delete.
@@ -12,14 +12,17 @@ def test_setitem_error_msmgs(self):
12
12
13
13
# GH 7432
14
14
df = DataFrame (
15
- {"foo" : ["a" , "b" , "c" ], "bar" : [1 , 2 , 3 ], "baz" : ["d" , "e" , "f" ]}
16
- ).set_index ("foo" )
17
- s = DataFrame (
18
- {"foo" : ["a" , "b" , "c" , "a" ], "fiz" : ["g" , "h" , "i" , "j" ]}
19
- ).set_index ("foo" )
15
+ {"bar" : [1 , 2 , 3 ], "baz" : ["d" , "e" , "f" ]},
16
+ index = Index (["a" , "b" , "c" ], name = "foo" ),
17
+ )
18
+ ser = Series (
19
+ ["g" , "h" , "i" , "j" ],
20
+ index = Index (["a" , "b" , "c" , "a" ], name = "foo" ),
21
+ name = "fiz" ,
22
+ )
20
23
msg = "cannot reindex from a duplicate axis"
21
24
with pytest .raises (ValueError , match = msg ):
22
- df ["newcol" ] = s
25
+ df ["newcol" ] = ser
23
26
24
27
# GH 4107, more descriptive error message
25
28
df = DataFrame (np .random .randint (0 , 2 , (4 , 4 )), columns = ["a" , "b" , "c" , "d" ])
0 commit comments