Skip to content

Commit ffca57a

Browse files
committed
Merge pull request #5658 from jreback/is_copy
API: change _is_copy to is_copy attribute on pandas objects GH(5650)
2 parents 81053f9 + 8909fd0 commit ffca57a

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

pandas/core/generic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ class NDFrame(PandasObject):
7777
axes : list
7878
copy : boolean, default False
7979
"""
80-
_internal_names = ['_data', 'name', '_cacher', '_is_copy', '_subtyp',
80+
_internal_names = ['_data', 'name', '_cacher', 'is_copy', '_subtyp',
8181
'_index', '_default_kind', '_default_fill_value']
8282
_internal_names_set = set(_internal_names)
8383
_metadata = []
84-
_is_copy = None
84+
is_copy = None
8585

8686
def __init__(self, data, axes=None, copy=False, dtype=None,
8787
fastpath=False):
@@ -96,7 +96,7 @@ def __init__(self, data, axes=None, copy=False, dtype=None,
9696
for i, ax in enumerate(axes):
9797
data = data.reindex_axis(ax, axis=i)
9898

99-
object.__setattr__(self, '_is_copy', False)
99+
object.__setattr__(self, 'is_copy', False)
100100
object.__setattr__(self, '_data', data)
101101
object.__setattr__(self, '_item_cache', {})
102102

@@ -1016,15 +1016,15 @@ def _set_item(self, key, value):
10161016

10171017
def _setitem_copy(self, copy):
10181018
""" set the _is_copy of the iiem """
1019-
self._is_copy = copy
1019+
self.is_copy = copy
10201020
return self
10211021

10221022
def _check_setitem_copy(self, stacklevel=4):
10231023
""" validate if we are doing a settitem on a chained copy.
10241024
10251025
If you call this function, be sure to set the stacklevel such that the
10261026
user will see the error *at the level of setting*"""
1027-
if self._is_copy:
1027+
if self.is_copy:
10281028
value = config.get_option('mode.chained_assignment')
10291029

10301030
t = ("A value is trying to be set on a copy of a slice from a "

pandas/tests/test_frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11125,7 +11125,7 @@ def test_xs_view(self):
1112511125
self.assert_((dm.xs(2) == 5).all())
1112611126

1112711127
# prior to chained assignment (GH5390)
11128-
# this would raise, but now just rrens a copy (and sets _is_copy)
11128+
# this would raise, but now just returns a copy (and sets is_copy)
1112911129
# TODO (?): deal with mixed-type fiasco?
1113011130
# with assertRaisesRegexp(TypeError, 'cannot get view of mixed-type'):
1113111131
# self.mixed_frame.xs(self.mixed_frame.index[2], copy=False)

pandas/tests/test_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1380,10 +1380,10 @@ def test_set_value_keeps_names(self):
13801380
columns=['one', 'two', 'three', 'four'],
13811381
index=idx)
13821382
df = df.sortlevel()
1383-
self.assert_(df._is_copy is False)
1383+
self.assert_(df.is_copy is False)
13841384
self.assertEqual(df.index.names, ('Name', 'Number'))
13851385
df = df.set_value(('grethe', '4'), 'one', 99.34)
1386-
self.assert_(df._is_copy is False)
1386+
self.assert_(df.is_copy is False)
13871387
self.assertEqual(df.index.names, ('Name', 'Number'))
13881388

13891389
def test_names(self):

pandas/tests/test_indexing.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1776,19 +1776,19 @@ def test_detect_chained_assignment(self):
17761776
# work with the chain
17771777
expected = DataFrame([[-5,1],[-6,3]],columns=list('AB'))
17781778
df = DataFrame(np.arange(4).reshape(2,2),columns=list('AB'),dtype='int64')
1779-
self.assert_(not df._is_copy)
1779+
self.assert_(not df.is_copy)
17801780

17811781
df['A'][0] = -5
17821782
df['A'][1] = -6
17831783
assert_frame_equal(df, expected)
17841784

17851785
expected = DataFrame([[-5,2],[np.nan,3.]],columns=list('AB'))
17861786
df = DataFrame({ 'A' : Series(range(2),dtype='int64'), 'B' : np.array(np.arange(2,4),dtype=np.float64)})
1787-
self.assert_(not df._is_copy)
1787+
self.assert_(not df.is_copy)
17881788
df['A'][0] = -5
17891789
df['A'][1] = np.nan
17901790
assert_frame_equal(df, expected)
1791-
self.assert_(not df['A']._is_copy)
1791+
self.assert_(not df['A'].is_copy)
17921792

17931793
# using a copy (the chain), fails
17941794
df = DataFrame({ 'A' : Series(range(2),dtype='int64'), 'B' : np.array(np.arange(2,4),dtype=np.float64)})
@@ -1800,7 +1800,7 @@ def f():
18001800
df = DataFrame({'a' : ['one', 'one', 'two',
18011801
'three', 'two', 'one', 'six'],
18021802
'c' : Series(range(7),dtype='int64') })
1803-
self.assert_(not df._is_copy)
1803+
self.assert_(not df.is_copy)
18041804
expected = DataFrame({'a' : ['one', 'one', 'two',
18051805
'three', 'two', 'one', 'six'],
18061806
'c' : [42,42,2,3,4,42,6]})
@@ -1826,10 +1826,10 @@ def f():
18261826
with tm.assert_produces_warning(expected_warning=com.SettingWithCopyWarning):
18271827
df.loc[0]['A'] = 111
18281828

1829-
# make sure that _is_copy is picked up reconstruction
1829+
# make sure that is_copy is picked up reconstruction
18301830
# GH5475
18311831
df = DataFrame({"A": [1,2]})
1832-
self.assert_(df._is_copy is False)
1832+
self.assert_(df.is_copy is False)
18331833
with tm.ensure_clean('__tmp__pickle') as path:
18341834
df.to_pickle(path)
18351835
df2 = pd.read_pickle(path)
@@ -1854,21 +1854,21 @@ def random_text(nobs=100):
18541854

18551855
# always a copy
18561856
x = df.iloc[[0,1,2]]
1857-
self.assert_(x._is_copy is True)
1857+
self.assert_(x.is_copy is True)
18581858
x = df.iloc[[0,1,2,4]]
1859-
self.assert_(x._is_copy is True)
1859+
self.assert_(x.is_copy is True)
18601860

18611861
# explicity copy
18621862
indexer = df.letters.apply(lambda x : len(x) > 10)
18631863
df = df.ix[indexer].copy()
1864-
self.assert_(df._is_copy is False)
1864+
self.assert_(df.is_copy is False)
18651865
df['letters'] = df['letters'].apply(str.lower)
18661866

18671867
# implicity take
18681868
df = random_text(100000)
18691869
indexer = df.letters.apply(lambda x : len(x) > 10)
18701870
df = df.ix[indexer]
1871-
self.assert_(df._is_copy is True)
1871+
self.assert_(df.is_copy is True)
18721872
df.loc[:,'letters'] = df['letters'].apply(str.lower)
18731873

18741874
# this will raise
@@ -1880,7 +1880,7 @@ def random_text(nobs=100):
18801880

18811881
# an identical take, so no copy
18821882
df = DataFrame({'a' : [1]}).dropna()
1883-
self.assert_(df._is_copy is False)
1883+
self.assert_(df.is_copy is False)
18841884
df['a'] += 1
18851885

18861886
pd.set_option('chained_assignment','warn')

0 commit comments

Comments
 (0)