@@ -177,10 +177,10 @@ def test_frame_setitem(indexer, using_copy_on_write):
177177@pytest .mark .parametrize (
178178 "indexer" , [0 , [0 , 1 ], slice (0 , 2 ), np .array ([True , False , True ])]
179179)
180- def test_series_iloc_setitem (indexer , using_copy_on_write ):
180+ def test_series_iloc_setitem (indexer ):
181181 df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
182182
183- if using_copy_on_write :
183+ with option_context ( "chained_assignment" , "warn" ) :
184184 with tm .raises_chained_assignment_error ():
185185 df ["a" ].iloc [indexer ] = 0
186186
@@ -191,18 +191,20 @@ def test_series_iloc_setitem(indexer, using_copy_on_write):
191191def test_frame_iloc_setitem (indexer , using_copy_on_write ):
192192 df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
193193
194- if using_copy_on_write :
195- with tm .raises_chained_assignment_error ():
194+ extra_warnings = () if using_copy_on_write else (SettingWithCopyWarning ,)
195+
196+ with option_context ("chained_assignment" , "warn" ):
197+ with tm .raises_chained_assignment_error (extra_warnings = extra_warnings ):
196198 df [0 :3 ].iloc [indexer ] = 10
197199
198200
199201@pytest .mark .parametrize (
200202 "indexer" , [0 , [0 , 1 ], slice (0 , 2 ), np .array ([True , False , True ])]
201203)
202- def test_series_loc_setitem (indexer , using_copy_on_write ):
204+ def test_series_loc_setitem (indexer ):
203205 df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
204206
205- if using_copy_on_write :
207+ with option_context ( "chained_assignment" , "warn" ) :
206208 with tm .raises_chained_assignment_error ():
207209 df ["a" ].loc [indexer ] = 0
208210
@@ -213,38 +215,40 @@ def test_series_loc_setitem(indexer, using_copy_on_write):
213215def test_frame_loc_setitem (indexer , using_copy_on_write ):
214216 df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
215217
216- if using_copy_on_write :
217- with tm .raises_chained_assignment_error ():
218+ extra_warnings = () if using_copy_on_write else (SettingWithCopyWarning ,)
219+
220+ with option_context ("chained_assignment" , "warn" ):
221+ with tm .raises_chained_assignment_error (extra_warnings = extra_warnings ):
218222 df [0 :3 ].loc [indexer ] = 10
219223
220224
221- def test_series_at_setitem (using_copy_on_write ):
225+ def test_series_at_setitem ():
222226 df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
223227
224- if using_copy_on_write :
228+ with option_context ( "chained_assignment" , "warn" ) :
225229 with tm .raises_chained_assignment_error ():
226230 df ["a" ].at [0 ] = 0
227231
228232
229- def test_frame_at_setitem (using_copy_on_write ):
233+ def test_frame_at_setitem ():
230234 df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
231235
232- if using_copy_on_write :
236+ with option_context ( "chained_assignment" , "warn" ) :
233237 with tm .raises_chained_assignment_error ():
234238 df [0 :3 ].at [0 , "a" ] = 10
235239
236240
237- def test_series_iat_setitem (using_copy_on_write ):
241+ def test_series_iat_setitem ():
238242 df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
239243
240- if using_copy_on_write :
244+ with option_context ( "chained_assignment" , "warn" ) :
241245 with tm .raises_chained_assignment_error ():
242246 df ["a" ].iat [0 ] = 0
243247
244248
245- def test_frame_iat_setitem (using_copy_on_write ):
249+ def test_frame_iat_setitem ():
246250 df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
247251
248- if using_copy_on_write :
252+ with option_context ( "chained_assignment" , "warn" ) :
249253 with tm .raises_chained_assignment_error ():
250254 df [0 :3 ].iat [0 , 0 ] = 10
0 commit comments