8
8
from pandas import (compat , DataFrame , option_context ,
9
9
Series , MultiIndex , date_range , Timestamp )
10
10
from pandas .util import testing as tm
11
+ from pandas .core .common import SettingWithCopyError , SettingWithCopyWarning
11
12
12
13
13
14
class TestCaching (object ):
@@ -136,7 +137,7 @@ def test_detect_chained_assignment(self):
136
137
expected = DataFrame ([[- 5 , 1 ], [- 6 , 3 ]], columns = list ('AB' ))
137
138
df = DataFrame (np .arange (4 ).reshape (2 , 2 ),
138
139
columns = list ('AB' ), dtype = 'int64' )
139
- assert df .is_copy is None
140
+ assert df ._is_copy is None
140
141
141
142
df ['A' ][0 ] = - 5
142
143
df ['A' ][1 ] = - 6
@@ -145,15 +146,15 @@ def test_detect_chained_assignment(self):
145
146
# test with the chaining
146
147
df = DataFrame ({'A' : Series (range (2 ), dtype = 'int64' ),
147
148
'B' : np .array (np .arange (2 , 4 ), dtype = np .float64 )})
148
- assert df .is_copy is None
149
+ assert df ._is_copy is None
149
150
150
151
with pytest .raises (com .SettingWithCopyError ):
151
152
df ['A' ][0 ] = - 5
152
153
153
154
with pytest .raises (com .SettingWithCopyError ):
154
155
df ['A' ][1 ] = np .nan
155
156
156
- assert df ['A' ].is_copy is None
157
+ assert df ['A' ]._is_copy is None
157
158
158
159
# Using a copy (the chain), fails
159
160
df = DataFrame ({'A' : Series (range (2 ), dtype = 'int64' ),
@@ -166,7 +167,7 @@ def test_detect_chained_assignment(self):
166
167
df = DataFrame ({'a' : ['one' , 'one' , 'two' , 'three' ,
167
168
'two' , 'one' , 'six' ],
168
169
'c' : Series (range (7 ), dtype = 'int64' )})
169
- assert df .is_copy is None
170
+ assert df ._is_copy is None
170
171
171
172
with pytest .raises (com .SettingWithCopyError ):
172
173
indexer = df .a .str .startswith ('o' )
@@ -186,7 +187,7 @@ def test_detect_chained_assignment(self):
186
187
187
188
# gh-5475: Make sure that is_copy is picked up reconstruction
188
189
df = DataFrame ({"A" : [1 , 2 ]})
189
- assert df .is_copy is None
190
+ assert df ._is_copy is None
190
191
191
192
with tm .ensure_clean ('__tmp__pickle' ) as path :
192
193
df .to_pickle (path )
@@ -211,39 +212,39 @@ def random_text(nobs=100):
211
212
212
213
# Always a copy
213
214
x = df .iloc [[0 , 1 , 2 ]]
214
- assert x .is_copy is not None
215
+ assert x ._is_copy is not None
215
216
216
217
x = df .iloc [[0 , 1 , 2 , 4 ]]
217
- assert x .is_copy is not None
218
+ assert x ._is_copy is not None
218
219
219
220
# Explicitly copy
220
221
indexer = df .letters .apply (lambda x : len (x ) > 10 )
221
222
df = df .loc [indexer ].copy ()
222
223
223
- assert df .is_copy is None
224
+ assert df ._is_copy is None
224
225
df ['letters' ] = df ['letters' ].apply (str .lower )
225
226
226
227
# Implicitly take
227
228
df = random_text (100000 )
228
229
indexer = df .letters .apply (lambda x : len (x ) > 10 )
229
230
df = df .loc [indexer ]
230
231
231
- assert df .is_copy is not None
232
+ assert df ._is_copy is not None
232
233
df ['letters' ] = df ['letters' ].apply (str .lower )
233
234
234
235
# Implicitly take 2
235
236
df = random_text (100000 )
236
237
indexer = df .letters .apply (lambda x : len (x ) > 10 )
237
238
238
239
df = df .loc [indexer ]
239
- assert df .is_copy is not None
240
+ assert df ._is_copy is not None
240
241
df .loc [:, 'letters' ] = df ['letters' ].apply (str .lower )
241
242
242
243
# Should be ok even though it's a copy!
243
- assert df .is_copy is None
244
+ assert df ._is_copy is None
244
245
245
246
df ['letters' ] = df ['letters' ].apply (str .lower )
246
- assert df .is_copy is None
247
+ assert df ._is_copy is None
247
248
248
249
df = random_text (100000 )
249
250
indexer = df .letters .apply (lambda x : len (x ) > 10 )
@@ -252,7 +253,7 @@ def random_text(nobs=100):
252
253
253
254
# an identical take, so no copy
254
255
df = DataFrame ({'a' : [1 ]}).dropna ()
255
- assert df .is_copy is None
256
+ assert df ._is_copy is None
256
257
df ['a' ] += 1
257
258
258
259
# Inplace ops, originally from:
@@ -418,3 +419,14 @@ def test_cache_updating(self):
418
419
tm .assert_frame_equal (df , expected )
419
420
expected = Series ([0 , 0 , 0 , 2 , 0 ], name = 'f' )
420
421
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