@@ -43,10 +43,12 @@ def test_partial_setting(self):
43
43
# iloc/iat raise
44
44
s = s_orig .copy ()
45
45
46
- with pytest .raises (IndexError ):
46
+ msg = "iloc cannot enlarge its target object"
47
+ with pytest .raises (IndexError , match = msg ):
47
48
s .iloc [3 ] = 5.0
48
49
49
- with pytest .raises (IndexError ):
50
+ msg = "index 3 is out of bounds for axis 0 with size 3"
51
+ with pytest .raises (IndexError , match = msg ):
50
52
s .iat [3 ] = 5.0
51
53
52
54
# ## frame ##
@@ -58,10 +60,12 @@ def test_partial_setting(self):
58
60
# iloc/iat raise
59
61
df = df_orig .copy ()
60
62
61
- with pytest .raises (IndexError ):
63
+ msg = "iloc cannot enlarge its target object"
64
+ with pytest .raises (IndexError , match = msg ):
62
65
df .iloc [4 , 2 ] = 5.0
63
66
64
- with pytest .raises (IndexError ):
67
+ msg = "index 2 is out of bounds for axis 0 with size 2"
68
+ with pytest .raises (IndexError , match = msg ):
65
69
df .iat [4 , 2 ] = 5.0
66
70
67
71
# row setting where it exists
@@ -162,7 +166,8 @@ def test_partial_setting_mixed_dtype(self):
162
166
# list-like must conform
163
167
df = DataFrame (columns = ["A" , "B" ])
164
168
165
- with pytest .raises (ValueError ):
169
+ msg = "cannot set a row with mismatched columns"
170
+ with pytest .raises (ValueError , match = msg ):
166
171
df .loc [0 ] = [1 , 2 , 3 ]
167
172
168
173
# TODO: #15657, these are left as object and not coerced
@@ -330,10 +335,12 @@ def test_partial_set_invalid(self):
330
335
df = orig .copy ()
331
336
332
337
# don't allow not string inserts
333
- with pytest .raises (TypeError ):
338
+ msg = "cannot insert DatetimeIndex with incompatible label"
339
+
340
+ with pytest .raises (TypeError , match = msg ):
334
341
df .loc [100.0 , :] = df .iloc [0 ]
335
342
336
- with pytest .raises (TypeError ):
343
+ with pytest .raises (TypeError , match = msg ):
337
344
df .loc [100 , :] = df .iloc [0 ]
338
345
339
346
# allow object conversion here
@@ -375,13 +382,16 @@ def test_partial_set_empty_frame(self):
375
382
# frame
376
383
df = DataFrame ()
377
384
378
- with pytest .raises (ValueError ):
385
+ msg = "cannot set a frame with no defined columns"
386
+
387
+ with pytest .raises (ValueError , match = msg ):
379
388
df .loc [1 ] = 1
380
389
381
- with pytest .raises (ValueError ):
390
+ with pytest .raises (ValueError , match = msg ):
382
391
df .loc [1 ] = Series ([1 ], index = ["foo" ])
383
392
384
- with pytest .raises (ValueError ):
393
+ msg = "cannot set a frame with no defined index and a scalar"
394
+ with pytest .raises (ValueError , match = msg ):
385
395
df .loc [:, 1 ] = 1
386
396
387
397
# these work as they don't really change
0 commit comments