@@ -2022,19 +2022,19 @@ def test_detect_chained_assignment(self):
20222022 # work with the chain
20232023 expected = DataFrame ([[- 5 ,1 ],[- 6 ,3 ]],columns = list ('AB' ))
20242024 df = DataFrame (np .arange (4 ).reshape (2 ,2 ),columns = list ('AB' ),dtype = 'int64' )
2025- self .assert_ (not df .is_copy )
2025+ self .assert_ (df .is_copy is None )
20262026
20272027 df ['A' ][0 ] = - 5
20282028 df ['A' ][1 ] = - 6
20292029 assert_frame_equal (df , expected )
20302030
20312031 expected = DataFrame ([[- 5 ,2 ],[np .nan ,3. ]],columns = list ('AB' ))
20322032 df = DataFrame ({ 'A' : Series (range (2 ),dtype = 'int64' ), 'B' : np .array (np .arange (2 ,4 ),dtype = np .float64 )})
2033- self .assert_ (not df .is_copy )
2033+ self .assert_ (df .is_copy is None )
20342034 df ['A' ][0 ] = - 5
20352035 df ['A' ][1 ] = np .nan
20362036 assert_frame_equal (df , expected )
2037- self .assert_ (not df ['A' ].is_copy )
2037+ self .assert_ (df ['A' ].is_copy is None )
20382038
20392039 # using a copy (the chain), fails
20402040 df = DataFrame ({ 'A' : Series (range (2 ),dtype = 'int64' ), 'B' : np .array (np .arange (2 ,4 ),dtype = np .float64 )})
@@ -2046,7 +2046,7 @@ def f():
20462046 df = DataFrame ({'a' : ['one' , 'one' , 'two' ,
20472047 'three' , 'two' , 'one' , 'six' ],
20482048 'c' : Series (range (7 ),dtype = 'int64' ) })
2049- self .assert_ (not df .is_copy )
2049+ self .assert_ (df .is_copy is None )
20502050 expected = DataFrame ({'a' : ['one' , 'one' , 'two' ,
20512051 'three' , 'two' , 'one' , 'six' ],
20522052 'c' : [42 ,42 ,2 ,3 ,4 ,42 ,6 ]})
@@ -2075,7 +2075,7 @@ def f():
20752075 # make sure that is_copy is picked up reconstruction
20762076 # GH5475
20772077 df = DataFrame ({"A" : [1 ,2 ]})
2078- self .assert_ (df .is_copy is False )
2078+ self .assert_ (df .is_copy is None )
20792079 with tm .ensure_clean ('__tmp__pickle' ) as path :
20802080 df .to_pickle (path )
20812081 df2 = pd .read_pickle (path )
@@ -2100,33 +2100,42 @@ def random_text(nobs=100):
21002100
21012101 # always a copy
21022102 x = df .iloc [[0 ,1 ,2 ]]
2103- self .assert_ (x .is_copy is True )
2103+ self .assert_ (x .is_copy is not None )
21042104 x = df .iloc [[0 ,1 ,2 ,4 ]]
2105- self .assert_ (x .is_copy is True )
2105+ self .assert_ (x .is_copy is not None )
21062106
21072107 # explicity copy
21082108 indexer = df .letters .apply (lambda x : len (x ) > 10 )
21092109 df = df .ix [indexer ].copy ()
2110- self .assert_ (df .is_copy is False )
2110+ self .assert_ (df .is_copy is None )
21112111 df ['letters' ] = df ['letters' ].apply (str .lower )
21122112
21132113 # implicity take
21142114 df = random_text (100000 )
21152115 indexer = df .letters .apply (lambda x : len (x ) > 10 )
21162116 df = df .ix [indexer ]
2117- self .assert_ (df .is_copy is True )
2117+ self .assert_ (df .is_copy is not None )
2118+ df ['letters' ] = df ['letters' ].apply (str .lower )
2119+
2120+ # implicity take 2
2121+ df = random_text (100000 )
2122+ indexer = df .letters .apply (lambda x : len (x ) > 10 )
2123+ df = df .ix [indexer ]
2124+ self .assert_ (df .is_copy is not None )
21182125 df .loc [:,'letters' ] = df ['letters' ].apply (str .lower )
21192126
2120- # this will raise
2121- #df['letters'] = df['letters'].apply(str.lower)
2127+ # should be ok even though its a copy!
2128+ self .assert_ (df .is_copy is None )
2129+ df ['letters' ] = df ['letters' ].apply (str .lower )
2130+ self .assert_ (df .is_copy is None )
21222131
21232132 df = random_text (100000 )
21242133 indexer = df .letters .apply (lambda x : len (x ) > 10 )
21252134 df .ix [indexer ,'letters' ] = df .ix [indexer ,'letters' ].apply (str .lower )
21262135
21272136 # an identical take, so no copy
21282137 df = DataFrame ({'a' : [1 ]}).dropna ()
2129- self .assert_ (df .is_copy is False )
2138+ self .assert_ (df .is_copy is None )
21302139 df ['a' ] += 1
21312140
21322141 # inplace ops
@@ -2165,7 +2174,15 @@ def f():
21652174 df [['c' ]][mask ] = df [['b' ]][mask ]
21662175 self .assertRaises (com .SettingWithCopyError , f )
21672176
2168- pd .set_option ('chained_assignment' ,'warn' )
2177+ # false positives GH6025
2178+ df = DataFrame ({'column1' :['a' , 'a' , 'a' ], 'column2' : [4 ,8 ,9 ] })
2179+ str (df )
2180+ df ['column1' ] = df ['column1' ] + 'b'
2181+ str (df )
2182+ df = df [df ['column2' ]!= 8 ]
2183+ str (df )
2184+ df ['column1' ] = df ['column1' ] + 'c'
2185+ str (df )
21692186
21702187 def test_float64index_slicing_bug (self ):
21712188 # GH 5557, related to slicing a float index
0 commit comments