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