88from pandas import (compat , DataFrame , option_context ,
99 Series , MultiIndex , date_range , Timestamp )
1010from pandas .util import testing as tm
11+ from pandas .core .common import SettingWithCopyError , SettingWithCopyWarning
1112
1213
1314class TestCaching (object ):
@@ -136,7 +137,7 @@ def test_detect_chained_assignment(self):
136137 expected = DataFrame ([[- 5 , 1 ], [- 6 , 3 ]], columns = list ('AB' ))
137138 df = DataFrame (np .arange (4 ).reshape (2 , 2 ),
138139 columns = list ('AB' ), dtype = 'int64' )
139- assert df .is_copy is None
140+ assert df ._is_copy is None
140141
141142 df ['A' ][0 ] = - 5
142143 df ['A' ][1 ] = - 6
@@ -145,15 +146,15 @@ def test_detect_chained_assignment(self):
145146 # test with the chaining
146147 df = DataFrame ({'A' : Series (range (2 ), dtype = 'int64' ),
147148 'B' : np .array (np .arange (2 , 4 ), dtype = np .float64 )})
148- assert df .is_copy is None
149+ assert df ._is_copy is None
149150
150151 with pytest .raises (com .SettingWithCopyError ):
151152 df ['A' ][0 ] = - 5
152153
153154 with pytest .raises (com .SettingWithCopyError ):
154155 df ['A' ][1 ] = np .nan
155156
156- assert df ['A' ].is_copy is None
157+ assert df ['A' ]._is_copy is None
157158
158159 # Using a copy (the chain), fails
159160 df = DataFrame ({'A' : Series (range (2 ), dtype = 'int64' ),
@@ -166,7 +167,7 @@ def test_detect_chained_assignment(self):
166167 df = DataFrame ({'a' : ['one' , 'one' , 'two' , 'three' ,
167168 'two' , 'one' , 'six' ],
168169 'c' : Series (range (7 ), dtype = 'int64' )})
169- assert df .is_copy is None
170+ assert df ._is_copy is None
170171
171172 with pytest .raises (com .SettingWithCopyError ):
172173 indexer = df .a .str .startswith ('o' )
@@ -186,7 +187,7 @@ def test_detect_chained_assignment(self):
186187
187188 # gh-5475: Make sure that is_copy is picked up reconstruction
188189 df = DataFrame ({"A" : [1 , 2 ]})
189- assert df .is_copy is None
190+ assert df ._is_copy is None
190191
191192 with tm .ensure_clean ('__tmp__pickle' ) as path :
192193 df .to_pickle (path )
@@ -211,39 +212,39 @@ def random_text(nobs=100):
211212
212213 # Always a copy
213214 x = df .iloc [[0 , 1 , 2 ]]
214- assert x .is_copy is not None
215+ assert x ._is_copy is not None
215216
216217 x = df .iloc [[0 , 1 , 2 , 4 ]]
217- assert x .is_copy is not None
218+ assert x ._is_copy is not None
218219
219220 # Explicitly copy
220221 indexer = df .letters .apply (lambda x : len (x ) > 10 )
221222 df = df .loc [indexer ].copy ()
222223
223- assert df .is_copy is None
224+ assert df ._is_copy is None
224225 df ['letters' ] = df ['letters' ].apply (str .lower )
225226
226227 # Implicitly take
227228 df = random_text (100000 )
228229 indexer = df .letters .apply (lambda x : len (x ) > 10 )
229230 df = df .loc [indexer ]
230231
231- assert df .is_copy is not None
232+ assert df ._is_copy is not None
232233 df ['letters' ] = df ['letters' ].apply (str .lower )
233234
234235 # Implicitly take 2
235236 df = random_text (100000 )
236237 indexer = df .letters .apply (lambda x : len (x ) > 10 )
237238
238239 df = df .loc [indexer ]
239- assert df .is_copy is not None
240+ assert df ._is_copy is not None
240241 df .loc [:, 'letters' ] = df ['letters' ].apply (str .lower )
241242
242243 # Should be ok even though it's a copy!
243- assert df .is_copy is None
244+ assert df ._is_copy is None
244245
245246 df ['letters' ] = df ['letters' ].apply (str .lower )
246- assert df .is_copy is None
247+ assert df ._is_copy is None
247248
248249 df = random_text (100000 )
249250 indexer = df .letters .apply (lambda x : len (x ) > 10 )
@@ -252,7 +253,7 @@ def random_text(nobs=100):
252253
253254 # an identical take, so no copy
254255 df = DataFrame ({'a' : [1 ]}).dropna ()
255- assert df .is_copy is None
256+ assert df ._is_copy is None
256257 df ['a' ] += 1
257258
258259 # Inplace ops, originally from:
@@ -418,3 +419,14 @@ def test_cache_updating(self):
418419 tm .assert_frame_equal (df , expected )
419420 expected = Series ([0 , 0 , 0 , 2 , 0 ], name = 'f' )
420421 tm .assert_series_equal (df .f , expected )
422+
423+ def test_deprecate_is_copy (self ):
424+ #GH18801
425+ df = DataFrame ({"A" : [1 , 2 , 3 ]})
426+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
427+ # getter
428+ is_copy = df .is_copy
429+
430+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
431+ # setter
432+ df .is_copy = "test deprecated is_copy"
0 commit comments