Skip to content

BUG: .iloc[:] and .loc[:] return a copy of the original object #13873 #16443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "iloc and loc return new object when slice is a tuple"
This reverts commit 5daffa8.
  • Loading branch information
margaret committed Jun 14, 2017
commit fd47ef0389f061ad4c167ec94e827c17061113c1
5 changes: 3 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def _getitem_tuple(self, tup):
return self._multi_take(tup)

# no shortcut needed
retval = self.obj.copy()
retval = self.obj
for i, key in enumerate(tup):
if i >= self.obj.ndim:
raise IndexingError('Too many indexers')
Expand All @@ -854,6 +854,7 @@ def _getitem_tuple(self, tup):
continue

retval = getattr(retval, self.name)._getitem_axis(key, axis=i)

return retval

def _multi_take_opportunity(self, tup):
Expand Down Expand Up @@ -1664,7 +1665,7 @@ def _getitem_tuple(self, tup):
except:
pass

retval = self.obj.copy()
retval = self.obj
axis = 0
for i, key in enumerate(tup):
if i >= self.obj.ndim:
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,5 +596,3 @@ def test_loc_identity_slice_returns_new_object(self):
# GH13873
df = DataFrame({'a': [1, 3, 5], 'b': [2, 4, 6]})
assert not df.iloc[:] is df
assert not df.iloc[:,:] is df
assert not df.iloc[pd.IndexSlice[:, :]] is df
2 changes: 0 additions & 2 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,5 +635,3 @@ def test_loc_identity_slice_returns_new_object(self):
# GH13873
df = DataFrame({'a': [1, 3, 5], 'b': [2, 4, 6]})
assert not df.loc[:] is df
assert not df.loc[:,:] is df
assert not df.loc[pd.IndexSlice[:, :]] is df