@@ -337,13 +337,24 @@ def f():
337
337
df2 ['y' ] = ['g' , 'h' , 'i' ]
338
338
339
339
def test_detect_chained_assignment_warnings (self ):
340
+ with option_context ("chained_assignment" , "warn" ):
341
+ df = DataFrame ({"A" : ["aaa" , "bbb" , "ccc" ], "B" : [1 , 2 , 3 ]})
340
342
341
- # warnings
342
- with option_context ('chained_assignment' , 'warn' ):
343
- df = DataFrame ({'A' : ['aaa' , 'bbb' , 'ccc' ], 'B' : [1 , 2 , 3 ]})
344
- with tm .assert_produces_warning (
345
- expected_warning = com .SettingWithCopyWarning ):
346
- df .loc [0 ]['A' ] = 111
343
+ with tm .assert_produces_warning (com .SettingWithCopyWarning ):
344
+ df .loc [0 ]["A" ] = 111
345
+
346
+ def test_detect_chained_assignment_warnings_filter_and_dupe_cols (self ):
347
+ # xref gh-13017.
348
+ with option_context ("chained_assignment" , "warn" ):
349
+ df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , - 9 ]],
350
+ columns = ["a" , "a" , "c" ])
351
+
352
+ with tm .assert_produces_warning (com .SettingWithCopyWarning ):
353
+ df .c .loc [df .c > 0 ] = None
354
+
355
+ expected = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , - 9 ]],
356
+ columns = ["a" , "a" , "c" ])
357
+ tm .assert_frame_equal (df , expected )
347
358
348
359
def test_chained_getitem_with_lists (self ):
349
360
0 commit comments