@@ -1980,19 +1980,19 @@ def test_detect_chained_assignment(self):
19801980 # work with the chain
19811981 expected = DataFrame ([[- 5 ,1 ],[- 6 ,3 ]],columns = list ('AB' ))
19821982 df = DataFrame (np .arange (4 ).reshape (2 ,2 ),columns = list ('AB' ),dtype = 'int64' )
1983- self .assert_ (not df .is_copy )
1983+ self .assert_ (df .is_copy is None )
19841984
19851985 df ['A' ][0 ] = - 5
19861986 df ['A' ][1 ] = - 6
19871987 assert_frame_equal (df , expected )
19881988
19891989 expected = DataFrame ([[- 5 ,2 ],[np .nan ,3. ]],columns = list ('AB' ))
19901990 df = DataFrame ({ 'A' : Series (range (2 ),dtype = 'int64' ), 'B' : np .array (np .arange (2 ,4 ),dtype = np .float64 )})
1991- self .assert_ (not df .is_copy )
1991+ self .assert_ (df .is_copy is None )
19921992 df ['A' ][0 ] = - 5
19931993 df ['A' ][1 ] = np .nan
19941994 assert_frame_equal (df , expected )
1995- self .assert_ (not df ['A' ].is_copy )
1995+ self .assert_ (df ['A' ].is_copy is None )
19961996
19971997 # using a copy (the chain), fails
19981998 df = DataFrame ({ 'A' : Series (range (2 ),dtype = 'int64' ), 'B' : np .array (np .arange (2 ,4 ),dtype = np .float64 )})
@@ -2004,7 +2004,7 @@ def f():
20042004 df = DataFrame ({'a' : ['one' , 'one' , 'two' ,
20052005 'three' , 'two' , 'one' , 'six' ],
20062006 'c' : Series (range (7 ),dtype = 'int64' ) })
2007- self .assert_ (not df .is_copy )
2007+ self .assert_ (df .is_copy is None )
20082008 expected = DataFrame ({'a' : ['one' , 'one' , 'two' ,
20092009 'three' , 'two' , 'one' , 'six' ],
20102010 'c' : [42 ,42 ,2 ,3 ,4 ,42 ,6 ]})
@@ -2033,7 +2033,7 @@ def f():
20332033 # make sure that is_copy is picked up reconstruction
20342034 # GH5475
20352035 df = DataFrame ({"A" : [1 ,2 ]})
2036- self .assert_ (df .is_copy is False )
2036+ self .assert_ (df .is_copy is None )
20372037 with tm .ensure_clean ('__tmp__pickle' ) as path :
20382038 df .to_pickle (path )
20392039 df2 = pd .read_pickle (path )
@@ -2058,33 +2058,42 @@ def random_text(nobs=100):
20582058
20592059 # always a copy
20602060 x = df .iloc [[0 ,1 ,2 ]]
2061- self .assert_ (x .is_copy is True )
2061+ self .assert_ (x .is_copy is not None )
20622062 x = df .iloc [[0 ,1 ,2 ,4 ]]
2063- self .assert_ (x .is_copy is True )
2063+ self .assert_ (x .is_copy is not None )
20642064
20652065 # explicity copy
20662066 indexer = df .letters .apply (lambda x : len (x ) > 10 )
20672067 df = df .ix [indexer ].copy ()
2068- self .assert_ (df .is_copy is False )
2068+ self .assert_ (df .is_copy is None )
20692069 df ['letters' ] = df ['letters' ].apply (str .lower )
20702070
20712071 # implicity take
20722072 df = random_text (100000 )
20732073 indexer = df .letters .apply (lambda x : len (x ) > 10 )
20742074 df = df .ix [indexer ]
2075- self .assert_ (df .is_copy is True )
2075+ self .assert_ (df .is_copy is not None )
2076+ df ['letters' ] = df ['letters' ].apply (str .lower )
2077+
2078+ # implicity take 2
2079+ df = random_text (100000 )
2080+ indexer = df .letters .apply (lambda x : len (x ) > 10 )
2081+ df = df .ix [indexer ]
2082+ self .assert_ (df .is_copy is not None )
20762083 df .loc [:,'letters' ] = df ['letters' ].apply (str .lower )
20772084
2078- # this will raise
2079- #df['letters'] = df['letters'].apply(str.lower)
2085+ # should be ok even though its a copy!
2086+ self .assert_ (df .is_copy is None )
2087+ df ['letters' ] = df ['letters' ].apply (str .lower )
2088+ self .assert_ (df .is_copy is None )
20802089
20812090 df = random_text (100000 )
20822091 indexer = df .letters .apply (lambda x : len (x ) > 10 )
20832092 df .ix [indexer ,'letters' ] = df .ix [indexer ,'letters' ].apply (str .lower )
20842093
20852094 # an identical take, so no copy
20862095 df = DataFrame ({'a' : [1 ]}).dropna ()
2087- self .assert_ (df .is_copy is False )
2096+ self .assert_ (df .is_copy is None )
20882097 df ['a' ] += 1
20892098
20902099 # inplace ops
@@ -2123,7 +2132,15 @@ def f():
21232132 df [['c' ]][mask ] = df [['b' ]][mask ]
21242133 self .assertRaises (com .SettingWithCopyError , f )
21252134
2126- pd .set_option ('chained_assignment' ,'warn' )
2135+ # false positives GH6025
2136+ df = DataFrame ({'column1' :['a' , 'a' , 'a' ], 'column2' : [4 ,8 ,9 ] })
2137+ str (df )
2138+ df ['column1' ] = df ['column1' ] + 'b'
2139+ str (df )
2140+ df = df [df ['column2' ]!= 8 ]
2141+ str (df )
2142+ df ['column1' ] = df ['column1' ] + 'c'
2143+ str (df )
21272144
21282145 def test_float64index_slicing_bug (self ):
21292146 # GH 5557, related to slicing a float index
0 commit comments