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