@@ -2022,19 +2022,19 @@ def test_detect_chained_assignment(self):
2022
2022
# work with the chain
2023
2023
expected = DataFrame ([[- 5 ,1 ],[- 6 ,3 ]],columns = list ('AB' ))
2024
2024
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 )
2026
2026
2027
2027
df ['A' ][0 ] = - 5
2028
2028
df ['A' ][1 ] = - 6
2029
2029
assert_frame_equal (df , expected )
2030
2030
2031
2031
expected = DataFrame ([[- 5 ,2 ],[np .nan ,3. ]],columns = list ('AB' ))
2032
2032
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 )
2034
2034
df ['A' ][0 ] = - 5
2035
2035
df ['A' ][1 ] = np .nan
2036
2036
assert_frame_equal (df , expected )
2037
- self .assert_ (not df ['A' ].is_copy )
2037
+ self .assert_ (df ['A' ].is_copy is None )
2038
2038
2039
2039
# using a copy (the chain), fails
2040
2040
df = DataFrame ({ 'A' : Series (range (2 ),dtype = 'int64' ), 'B' : np .array (np .arange (2 ,4 ),dtype = np .float64 )})
@@ -2046,7 +2046,7 @@ def f():
2046
2046
df = DataFrame ({'a' : ['one' , 'one' , 'two' ,
2047
2047
'three' , 'two' , 'one' , 'six' ],
2048
2048
'c' : Series (range (7 ),dtype = 'int64' ) })
2049
- self .assert_ (not df .is_copy )
2049
+ self .assert_ (df .is_copy is None )
2050
2050
expected = DataFrame ({'a' : ['one' , 'one' , 'two' ,
2051
2051
'three' , 'two' , 'one' , 'six' ],
2052
2052
'c' : [42 ,42 ,2 ,3 ,4 ,42 ,6 ]})
@@ -2075,7 +2075,7 @@ def f():
2075
2075
# make sure that is_copy is picked up reconstruction
2076
2076
# GH5475
2077
2077
df = DataFrame ({"A" : [1 ,2 ]})
2078
- self .assert_ (df .is_copy is False )
2078
+ self .assert_ (df .is_copy is None )
2079
2079
with tm .ensure_clean ('__tmp__pickle' ) as path :
2080
2080
df .to_pickle (path )
2081
2081
df2 = pd .read_pickle (path )
@@ -2100,33 +2100,42 @@ def random_text(nobs=100):
2100
2100
2101
2101
# always a copy
2102
2102
x = df .iloc [[0 ,1 ,2 ]]
2103
- self .assert_ (x .is_copy is True )
2103
+ self .assert_ (x .is_copy is not None )
2104
2104
x = df .iloc [[0 ,1 ,2 ,4 ]]
2105
- self .assert_ (x .is_copy is True )
2105
+ self .assert_ (x .is_copy is not None )
2106
2106
2107
2107
# explicity copy
2108
2108
indexer = df .letters .apply (lambda x : len (x ) > 10 )
2109
2109
df = df .ix [indexer ].copy ()
2110
- self .assert_ (df .is_copy is False )
2110
+ self .assert_ (df .is_copy is None )
2111
2111
df ['letters' ] = df ['letters' ].apply (str .lower )
2112
2112
2113
2113
# implicity take
2114
2114
df = random_text (100000 )
2115
2115
indexer = df .letters .apply (lambda x : len (x ) > 10 )
2116
2116
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 )
2118
2125
df .loc [:,'letters' ] = df ['letters' ].apply (str .lower )
2119
2126
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 )
2122
2131
2123
2132
df = random_text (100000 )
2124
2133
indexer = df .letters .apply (lambda x : len (x ) > 10 )
2125
2134
df .ix [indexer ,'letters' ] = df .ix [indexer ,'letters' ].apply (str .lower )
2126
2135
2127
2136
# an identical take, so no copy
2128
2137
df = DataFrame ({'a' : [1 ]}).dropna ()
2129
- self .assert_ (df .is_copy is False )
2138
+ self .assert_ (df .is_copy is None )
2130
2139
df ['a' ] += 1
2131
2140
2132
2141
# inplace ops
@@ -2165,7 +2174,15 @@ def f():
2165
2174
df [['c' ]][mask ] = df [['b' ]][mask ]
2166
2175
self .assertRaises (com .SettingWithCopyError , f )
2167
2176
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 )
2169
2186
2170
2187
def test_float64index_slicing_bug (self ):
2171
2188
# GH 5557, related to slicing a float index
0 commit comments