Skip to content

Commit 222bc9d

Browse files
committed
CLN: remove core/generic/_setitem_copy in favor of obj.is_copy
1 parent 507ffb5 commit 222bc9d

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

pandas/core/frame.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1566,11 +1566,14 @@ def _ixs(self, i, axis=0, copy=False):
15661566

15671567
# a location index by definition
15681568
i = _maybe_convert_indices(i, len(self._get_axis(axis)))
1569-
return self.reindex(i, takeable=True)._setitem_copy(True)
1569+
result = self.reindex(i, takeable=True)
1570+
copy=True
15701571
else:
15711572
new_values, copy = self._data.fast_2d_xs(i, copy=copy)
1572-
return Series(new_values, index=self.columns,
1573-
name=self.index[i])._setitem_copy(copy)
1573+
result = Series(new_values, index=self.columns,
1574+
name=self.index[i])
1575+
result.is_copy=copy
1576+
return result
15741577

15751578
# icol
15761579
else:
@@ -1677,11 +1680,10 @@ def _getitem_multilevel(self, key):
16771680
if self._is_mixed_type:
16781681
result = self.reindex(columns=new_columns)
16791682
result.columns = result_columns
1680-
result.is_copy=True
16811683
else:
16821684
new_values = self.values[:, loc]
16831685
result = DataFrame(new_values, index=self.index,
1684-
columns=result_columns)
1686+
columns=result_columns).__finalize__(self)
16851687
if len(result.columns) == 1:
16861688
top = result.columns[0]
16871689
if ((type(top) == str and top == '') or
@@ -1690,6 +1692,7 @@ def _getitem_multilevel(self, key):
16901692
if isinstance(result, Series):
16911693
result = Series(result, index=self.index, name=key)
16921694

1695+
result.is_copy=True
16931696
return result
16941697
else:
16951698
return self._get_item_cache(key)
@@ -2137,7 +2140,8 @@ def xs(self, key, axis=0, level=None, copy=True, drop_level=True):
21372140

21382141
new_values, copy = self._data.fast_2d_xs(loc, copy=copy)
21392142
result = Series(new_values, index=self.columns,
2140-
name=self.index[loc])._setitem_copy(copy)
2143+
name=self.index[loc])
2144+
result.is_copy=True
21412145

21422146
else:
21432147
result = self[loc]

pandas/core/generic.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,6 @@ def _set_item(self, key, value):
10221022
self._data.set(key, value)
10231023
self._clear_item_cache()
10241024

1025-
def _setitem_copy(self, copy):
1026-
""" set the _is_copy of the iiem """
1027-
self.is_copy = copy
1028-
return self
1029-
10301025
def _check_setitem_copy(self, stacklevel=4, t='setting'):
10311026
""" validate if we are doing a settitem on a chained copy.
10321027
@@ -1115,7 +1110,7 @@ def take(self, indices, axis=0, convert=True, is_copy=True):
11151110

11161111
# maybe set copy if we didn't actually change the index
11171112
if is_copy and not result._get_axis(axis).equals(self._get_axis(axis)):
1118-
result = result._setitem_copy(is_copy)
1113+
result.is_copy=is_copy
11191114

11201115
return result
11211116

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _setitem_with_indexer(self, indexer, value):
209209
labels = _safe_append_to_index(index, key)
210210
self.obj._data = self.obj.reindex_axis(labels, i)._data
211211
self.obj._maybe_update_cacher(clear=True)
212-
self.obj._setitem_copy(False)
212+
self.obj.is_copy=False
213213

214214
if isinstance(labels, MultiIndex):
215215
self.obj.sortlevel(inplace=True)

pandas/tests/test_multilevel.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,10 @@ def test_is_lexsorted(self):
11411141
self.assert_(index.lexsort_depth == 0)
11421142

11431143
def test_frame_getitem_view(self):
1144-
df = self.frame.T
1144+
df = self.frame.T.copy()
1145+
1146+
# this works because we are modifying the underlying array
1147+
# really a no-no
11451148
df['foo'].values[:] = 0
11461149
self.assert_((df['foo'].values == 0).all())
11471150

0 commit comments

Comments
 (0)