@@ -31,7 +31,11 @@ def test_setitem_ndarray_1d(self):
31
31
df ["bar" ] = np .zeros (10 , dtype = complex )
32
32
33
33
# invalid
34
- with pytest .raises (ValueError ):
34
+ msg = (
35
+ "cannot set using a multi-index selection "
36
+ "indexer with a different length than the value"
37
+ )
38
+ with pytest .raises (ValueError , match = msg ):
35
39
df .loc [df .index [2 :5 ], "bar" ] = np .array ([2.33j , 1.23 + 0.1j , 2.2 , 1.0 ])
36
40
37
41
# valid
@@ -48,7 +52,8 @@ def test_setitem_ndarray_1d(self):
48
52
df ["foo" ] = np .zeros (10 , dtype = np .float64 )
49
53
df ["bar" ] = np .zeros (10 , dtype = complex )
50
54
51
- with pytest .raises (ValueError ):
55
+ msg = "Must have equal len keys and value when setting with an iterable"
56
+ with pytest .raises (ValueError , match = msg ):
52
57
df [2 :5 ] = np .arange (1 , 4 ) * 1j
53
58
54
59
@pytest .mark .parametrize (
@@ -1055,13 +1060,13 @@ def test_1tuple_without_multiindex():
1055
1060
def test_duplicate_index_mistyped_key_raises_keyerror ():
1056
1061
# GH#29189 float_index.get_loc(None) should raise KeyError, not TypeError
1057
1062
ser = pd .Series ([2 , 5 , 6 , 8 ], index = [2.0 , 4.0 , 4.0 , 5.0 ])
1058
- with pytest .raises (KeyError ):
1063
+ with pytest .raises (KeyError , match = "None" ):
1059
1064
ser [None ]
1060
1065
1061
- with pytest .raises (KeyError ):
1066
+ with pytest .raises (KeyError , match = "None" ):
1062
1067
ser .index .get_loc (None )
1063
1068
1064
- with pytest .raises (KeyError ):
1069
+ with pytest .raises (KeyError , match = "None" ):
1065
1070
ser .index ._engine .get_loc (None )
1066
1071
1067
1072
0 commit comments