Skip to content

Commit 5d6e3f5

Browse files
committed
is_copy -> _parent
1 parent 3a0b7e0 commit 5d6e3f5

13 files changed

+73
-62
lines changed

pandas/core/frame.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ def _ixs(self, i, axis=0):
18251825
copy = isinstance(new_values,np.ndarray) and new_values.base is None
18261826
result = Series(new_values, index=self.columns,
18271827
name=self.index[i], dtype=new_values.dtype)
1828-
result._set_is_copy(self, copy=copy)
1828+
result._set_parent(self, copy=copy)
18291829
return result
18301830

18311831
# icol
@@ -1957,7 +1957,7 @@ def _getitem_multilevel(self, key):
19571957
if isinstance(result, Series):
19581958
result = self._constructor_sliced(result, index=self.index, name=key)
19591959

1960-
result._set_is_copy(self)
1960+
result._set_parent(self)
19611961
return result
19621962
else:
19631963
return self._get_item_cache(key)
@@ -2300,12 +2300,12 @@ def _set_item(self, key, value):
23002300

23012301
# if we have a multi-index (which potentially has dropped levels)
23022302
# need to raise
2303-
if isinstance(self.is_copy().columns, MultiIndex):
2303+
if isinstance(self._parent().columns, MultiIndex):
23042304
raise
23052305

23062306
# we have a chained assignment
23072307
# assign back to the original
2308-
self.is_copy().loc[self.index,key] = value
2308+
self._parent().loc[self.index,key] = value
23092309

23102310
def insert(self, loc, column, value, allow_duplicates=False):
23112311
"""

pandas/core/generic.py

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ class NDFrame(PandasObject):
7878
axes : list
7979
copy : boolean, default False
8080
"""
81-
_internal_names = ['_data', '_cacher', '_item_cache', '_cache',
82-
'is_copy', '_subtyp', '_index', '_allow_copy_on_write',
81+
_internal_names = ['_data', '_cacher', '_item_cache', '_cache', '_parent',
82+
'_subtyp', '_index', '_parent_copy_on_write',
8383
'_default_kind', '_default_fill_value', '_metadata',
8484
'__array_struct__', '__array_interface__']
8585
_internal_names_set = set(_internal_names)
8686
_accessors = frozenset([])
8787
_metadata = []
88-
_allow_copy_on_write = True
89-
is_copy = None
88+
_parent_copy_on_write = True
89+
_parent = None
9090

9191
def __init__(self, data, axes=None, copy=False, dtype=None,
9292
fastpath=False):
@@ -101,10 +101,22 @@ def __init__(self, data, axes=None, copy=False, dtype=None,
101101
for i, ax in enumerate(axes):
102102
data = data.reindex_axis(ax, axis=i)
103103

104-
object.__setattr__(self, 'is_copy', None)
104+
object.__setattr__(self, '_parent', None)
105105
object.__setattr__(self, '_data', data)
106106
object.__setattr__(self, '_item_cache', {})
107107

108+
def _get_is_copy(self):
109+
warnings.warn("is_copy is deprecated will be removed in a future release",
110+
FutureWarning)
111+
return None
112+
113+
def _set_is_copy(self, v):
114+
warnings.warn("is_copy is deprecated will be removed in a future release",
115+
FutureWarning)
116+
pass
117+
118+
is_copy = property(fget=_get_is_copy, fset=_set_is_copy)
119+
108120
def _validate_dtype(self, dtype):
109121
""" validate the passed dtype """
110122

@@ -1092,7 +1104,7 @@ def _get_item_cache(self, item):
10921104
res._set_as_cached(item, self)
10931105

10941106
# for a chain
1095-
res.is_copy = self.is_copy
1107+
res._parent = self._parent
10961108
return res
10971109

10981110
def _set_as_cached(self, item, cacher):
@@ -1144,7 +1156,7 @@ def _is_view(self):
11441156
""" boolean : return if I am a view of another array """
11451157
return self._data.is_view
11461158

1147-
def _maybe_update_cacher(self, clear=False, verify_is_copy=True):
1159+
def _maybe_update_cacher(self, clear=False, verify_parent=True):
11481160
"""
11491161
11501162
see if we need to update our parent cacher
@@ -1154,8 +1166,8 @@ def _maybe_update_cacher(self, clear=False, verify_is_copy=True):
11541166
----------
11551167
clear : boolean, default False
11561168
clear the item cache
1157-
verify_is_copy : boolean, default True
1158-
provide is_copy checks
1169+
verify_parent : boolean, default True
1170+
provide parent checks
11591171
11601172
"""
11611173

@@ -1173,7 +1185,7 @@ def _maybe_update_cacher(self, clear=False, verify_is_copy=True):
11731185
except:
11741186
pass
11751187

1176-
if verify_is_copy:
1188+
if verify_parent:
11771189
self._check_copy_on_write()
11781190

11791191
if clear:
@@ -1197,8 +1209,8 @@ def _slice(self, slobj, axis=0, kind=None):
11971209
result = result.__finalize__(self)
11981210

11991211
# mark this as a copy if we are not axis=0
1200-
is_copy = axis!=0
1201-
result._set_is_copy(self)
1212+
parent = axis!=0
1213+
result._set_parent(self)
12021214
return result
12031215

12041216
def _set_item(self, key, value):
@@ -1207,23 +1219,23 @@ def _set_item(self, key, value):
12071219
self._data.set(key, value)
12081220
self._clear_item_cache()
12091221

1210-
def _set_is_copy(self, ref=None, copy=True):
1222+
def _set_parent(self, ref=None, copy=True):
12111223
if not copy:
1212-
self.is_copy = None
1224+
self._parent = None
12131225
else:
12141226
if ref is not None:
1215-
self.is_copy = weakref.ref(ref)
1227+
self._parent = weakref.ref(ref)
12161228
else:
1217-
self.is_copy = None
1229+
self._parent = None
12181230

12191231
def _check_copy_on_write(self):
12201232

12211233
# we could have a copy-on-write scenario
1222-
if self.is_copy and self._allow_copy_on_write:
1234+
if self._parent and self._parent_copy_on_write:
12231235

12241236
# we have an exception
1225-
if isinstance(self.is_copy, Exception):
1226-
raise self.is_copy
1237+
if isinstance(self._parent, Exception):
1238+
raise self._parent
12271239

12281240
def get_names_for_obj(__really_unused_name__342424__):
12291241
"""Returns all named references for self"""
@@ -1255,14 +1267,14 @@ def get_names_for_obj(__really_unused_name__342424__):
12551267

12561268
# otherwise we have chained indexing, raise and error
12571269
gc.collect(2)
1258-
if self.is_copy() is not None:
1270+
if self._parent() is not None:
12591271
names = get_names_for_obj(self)
12601272
if not len(names):
12611273
raise SettingWithCopyError("chained indexing detected, you can fix this ......")
12621274

12631275
# provide copy-on-write
12641276
self._data = self._data.copy()
1265-
self.is_copy = None
1277+
self._parent = None
12661278

12671279
def _check_is_chained_assignment_possible(self):
12681280
"""
@@ -1279,7 +1291,7 @@ def _check_is_chained_assignment_possible(self):
12791291
if ref is not None:
12801292
self._check_copy_on_write()
12811293
return True
1282-
elif self.is_copy:
1294+
elif self._parent:
12831295
self._check_copy_on_write()
12841296
return False
12851297

@@ -1342,7 +1354,7 @@ def take(self, indices, axis=0, convert=True, is_copy=True):
13421354
# maybe set copy if we didn't actually change the index
13431355
if is_copy:
13441356
if not result._get_axis(axis).equals(self._get_axis(axis)):
1345-
result._set_is_copy(self)
1357+
result._set_parent(self)
13461358

13471359
return result
13481360

@@ -1485,7 +1497,7 @@ def xs(self, key, axis=0, level=None, copy=None, drop_level=True):
14851497
result = self.iloc[loc]
14861498
result.index = new_index
14871499

1488-
result._set_is_copy(self)
1500+
result._set_parent(self)
14891501
return result
14901502

14911503
_xs = xs
@@ -1608,14 +1620,14 @@ def drop(self, labels, axis=0, level=None, inplace=False, errors='raise'):
16081620
else:
16091621
return result
16101622

1611-
def _update_inplace(self, result, verify_is_copy=True):
1623+
def _update_inplace(self, result, verify_parent=True):
16121624
"""
16131625
replace self internals with result.
16141626
16151627
Parameters
16161628
----------
1617-
verify_is_copy : boolean, default True
1618-
provide is_copy checks
1629+
verify_parent : boolean, default True
1630+
provide parent checks
16191631
16201632
"""
16211633
# NOTE: This does *not* call __finalize__ and that's an explicit
@@ -1624,7 +1636,7 @@ def _update_inplace(self, result, verify_is_copy=True):
16241636
self._reset_cache()
16251637
self._clear_item_cache()
16261638
self._data = getattr(result,'_data',result)
1627-
self._maybe_update_cacher(verify_is_copy=verify_is_copy)
1639+
self._maybe_update_cacher(verify_parent=verify_parent)
16281640

16291641
def add_prefix(self, prefix):
16301642
"""

pandas/core/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ def _python_apply_general(self, f):
695695

696696
keys, values, mutated = self.grouper.apply(f, self._selected_obj,
697697
self.axis)
698-
self._selected_obj._allow_copy_on_write = True
698+
self._selected_obj._parent_copy_on_write = True
699699

700700
return self._wrap_applied_output(keys, values,
701701
not_indexed_same=mutated)
@@ -3596,7 +3596,7 @@ def sort_idx(self):
35963596
def _set_cow(self, data):
35973597
# we may mutate, so don't allow cow
35983598
try:
3599-
data._allow_copy_on_write=False
3599+
data._parent_copy_on_write=False
36003600
except AttributeError:
36013601
pass
36023602
return data

pandas/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _setitem_with_indexer(self, indexer, value):
273273
labels = index.insert(len(index),key)
274274
self.obj._data = self.obj.reindex_axis(labels, i)._data
275275
self.obj._maybe_update_cacher(clear=True)
276-
self.obj.is_copy=None
276+
self.obj._parent=None
277277

278278
nindexer.append(labels.get_loc(key))
279279

pandas/core/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def f(self, other):
191191
# this makes sure that we are aligned like the input
192192
# we are updating inplace so we want to ignore is_copy
193193
self._update_inplace(result.reindex_like(self,copy=False)._data,
194-
verify_is_copy=False)
194+
verify_parent=False)
195195

196196
return self
197197
return f

pandas/core/panel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,7 @@ def xs(self, key, axis=1, copy=None):
812812
axis_number = self._get_axis_number(axis)
813813
new_data = self._data.xs(key, axis=axis_number, copy=False)
814814
result = self._construct_return_type(new_data)
815-
copy = new_data.is_mixed_type
816-
result._set_is_copy(self, copy=copy)
815+
result._set_parent(self)
817816
return result
818817

819818
_xs = xs

pandas/core/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def setitem(key, value):
690690

691691
# we have a chained assignment
692692
# assign back to the original
693-
self.is_copy().loc[self.name,key] = value
693+
self._parent().loc[self.name,key] = value
694694
return
695695

696696
setitem(key, value)

pandas/src/reduce.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def apply_frame_axis0(object frame, object f, object names,
488488
# Need to infer if our low-level mucking is going to cause a segfault
489489
if n > 0:
490490
chunk = frame.iloc[starts[0]:ends[0]]
491-
chunk._allow_copy_on_write = False
491+
chunk._parent_copy_on_write = False
492492
shape_before = chunk.shape
493493
try:
494494
result = f(chunk)
@@ -509,7 +509,7 @@ def apply_frame_axis0(object frame, object f, object names,
509509
item_cache.clear() # ugh
510510

511511
object.__setattr__(slider.dummy, 'name', names[i])
512-
object.__setattr__(slider.dummy, '_allow_copy_on_write', False)
512+
object.__setattr__(slider.dummy, '_parent_copy_on_write', False)
513513
piece = f(slider.dummy)
514514

515515
# I'm paying the price for index-sharing, ugh

pandas/tests/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,10 +3534,10 @@ def test_set_value_keeps_names(self):
35343534
columns=['one', 'two', 'three', 'four'],
35353535
index=idx)
35363536
df = df.sortlevel()
3537-
self.assertIsNone(df.is_copy)
3537+
self.assertIsNone(df._parent)
35383538
self.assertEqual(df.index.names, ('Name', 'Number'))
35393539
df = df.set_value(('grethe', '4'), 'one', 99.34)
3540-
self.assertIsNone(df.is_copy)
3540+
self.assertIsNone(df._parent)
35413541
self.assertEqual(df.index.names, ('Name', 'Number'))
35423542

35433543
def test_names(self):

0 commit comments

Comments
 (0)