@@ -337,13 +337,24 @@ def f():
337337 df2 ['y' ] = ['g' , 'h' , 'i' ]
338338
339339 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 ]})
340342
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 )
347358
348359 def test_chained_getitem_with_lists (self ):
349360
0 commit comments