@@ -177,10 +177,10 @@ def test_frame_setitem(indexer, using_copy_on_write):
177
177
@pytest .mark .parametrize (
178
178
"indexer" , [0 , [0 , 1 ], slice (0 , 2 ), np .array ([True , False , True ])]
179
179
)
180
- def test_series_iloc_setitem (indexer , using_copy_on_write ):
180
+ def test_series_iloc_setitem (indexer ):
181
181
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
182
182
183
- if using_copy_on_write :
183
+ with option_context ( "chained_assignment" , "warn" ) :
184
184
with tm .raises_chained_assignment_error ():
185
185
df ["a" ].iloc [indexer ] = 0
186
186
@@ -191,18 +191,20 @@ def test_series_iloc_setitem(indexer, using_copy_on_write):
191
191
def test_frame_iloc_setitem (indexer , using_copy_on_write ):
192
192
df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
193
193
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 ):
196
198
df [0 :3 ].iloc [indexer ] = 10
197
199
198
200
199
201
@pytest .mark .parametrize (
200
202
"indexer" , [0 , [0 , 1 ], slice (0 , 2 ), np .array ([True , False , True ])]
201
203
)
202
- def test_series_loc_setitem (indexer , using_copy_on_write ):
204
+ def test_series_loc_setitem (indexer ):
203
205
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
204
206
205
- if using_copy_on_write :
207
+ with option_context ( "chained_assignment" , "warn" ) :
206
208
with tm .raises_chained_assignment_error ():
207
209
df ["a" ].loc [indexer ] = 0
208
210
@@ -213,38 +215,40 @@ def test_series_loc_setitem(indexer, using_copy_on_write):
213
215
def test_frame_loc_setitem (indexer , using_copy_on_write ):
214
216
df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
215
217
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 ):
218
222
df [0 :3 ].loc [indexer ] = 10
219
223
220
224
221
- def test_series_at_setitem (using_copy_on_write ):
225
+ def test_series_at_setitem ():
222
226
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
223
227
224
- if using_copy_on_write :
228
+ with option_context ( "chained_assignment" , "warn" ) :
225
229
with tm .raises_chained_assignment_error ():
226
230
df ["a" ].at [0 ] = 0
227
231
228
232
229
- def test_frame_at_setitem (using_copy_on_write ):
233
+ def test_frame_at_setitem ():
230
234
df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
231
235
232
- if using_copy_on_write :
236
+ with option_context ( "chained_assignment" , "warn" ) :
233
237
with tm .raises_chained_assignment_error ():
234
238
df [0 :3 ].at [0 , "a" ] = 10
235
239
236
240
237
- def test_series_iat_setitem (using_copy_on_write ):
241
+ def test_series_iat_setitem ():
238
242
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 })
239
243
240
- if using_copy_on_write :
244
+ with option_context ( "chained_assignment" , "warn" ) :
241
245
with tm .raises_chained_assignment_error ():
242
246
df ["a" ].iat [0 ] = 0
243
247
244
248
245
- def test_frame_iat_setitem (using_copy_on_write ):
249
+ def test_frame_iat_setitem ():
246
250
df = DataFrame ({"a" : [1 , 2 , 3 , 4 , 5 ], "b" : 1 })
247
251
248
- if using_copy_on_write :
252
+ with option_context ( "chained_assignment" , "warn" ) :
249
253
with tm .raises_chained_assignment_error ():
250
254
df [0 :3 ].iat [0 , 0 ] = 10
0 commit comments