@@ -155,10 +155,11 @@ def test_detect_chained_assignment(self):
155
155
)
156
156
assert df ._is_copy is None
157
157
158
- with pytest .raises (com .SettingWithCopyError ):
158
+ msg = "A value is trying to be set on a copy of a slice from a DataFrame"
159
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
159
160
df ["A" ][0 ] = - 5
160
161
161
- with pytest .raises (com .SettingWithCopyError ):
162
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
162
163
df ["A" ][1 ] = np .nan
163
164
164
165
assert df ["A" ]._is_copy is None
@@ -171,7 +172,7 @@ def test_detect_chained_assignment(self):
171
172
}
172
173
)
173
174
174
- with pytest .raises (com .SettingWithCopyError ):
175
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
175
176
df .loc [0 ]["A" ] = - 5
176
177
177
178
# Doc example
@@ -183,17 +184,17 @@ def test_detect_chained_assignment(self):
183
184
)
184
185
assert df ._is_copy is None
185
186
186
- with pytest .raises (com .SettingWithCopyError ):
187
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
187
188
indexer = df .a .str .startswith ("o" )
188
189
df [indexer ]["c" ] = 42
189
190
190
191
expected = DataFrame ({"A" : [111 , "bbb" , "ccc" ], "B" : [1 , 2 , 3 ]})
191
192
df = DataFrame ({"A" : ["aaa" , "bbb" , "ccc" ], "B" : [1 , 2 , 3 ]})
192
193
193
- with pytest .raises (com .SettingWithCopyError ):
194
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
194
195
df ["A" ][0 ] = 111
195
196
196
- with pytest .raises (com .SettingWithCopyError ):
197
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
197
198
df .loc [0 ]["A" ] = 111
198
199
199
200
df .loc [0 , "A" ] = 111
@@ -293,7 +294,7 @@ def random_text(nobs=100):
293
294
df = DataFrame (np .arange (0 , 9 ), columns = ["count" ])
294
295
df ["group" ] = "b"
295
296
296
- with pytest .raises (com .SettingWithCopyError ):
297
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
297
298
df .iloc [0 :5 ]["group" ] = "a"
298
299
299
300
# Mixed type setting but same dtype & changing dtype
@@ -306,13 +307,13 @@ def random_text(nobs=100):
306
307
)
307
308
)
308
309
309
- with pytest .raises (com .SettingWithCopyError ):
310
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
310
311
df .loc [2 ]["D" ] = "foo"
311
312
312
- with pytest .raises (com .SettingWithCopyError ):
313
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
313
314
df .loc [2 ]["C" ] = "foo"
314
315
315
- with pytest .raises (com .SettingWithCopyError ):
316
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
316
317
df ["C" ][2 ] = "foo"
317
318
318
319
def test_setting_with_copy_bug (self ):
@@ -340,8 +341,10 @@ def test_detect_chained_assignment_warnings_errors(self):
340
341
with option_context ("chained_assignment" , "warn" ):
341
342
with tm .assert_produces_warning (com .SettingWithCopyWarning ):
342
343
df .loc [0 ]["A" ] = 111
344
+
345
+ msg = "A value is trying to be set on a copy of a slice from a DataFrame"
343
346
with option_context ("chained_assignment" , "raise" ):
344
- with pytest .raises (com .SettingWithCopyError ):
347
+ with pytest .raises (com .SettingWithCopyError , match = msg ):
345
348
df .loc [0 ]["A" ] = 111
346
349
347
350
def test_detect_chained_assignment_warnings_filter_and_dupe_cols (self ):
0 commit comments