Skip to content

Commit

Permalink
iloc and loc return new object when slice is a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
margaret committed May 22, 2017
1 parent 91344b9 commit 5daffa8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 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
retval = self.obj.copy()
for i, key in enumerate(tup):
if i >= self.obj.ndim:
raise IndexingError('Too many indexers')
Expand All @@ -854,7 +854,6 @@ 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 @@ -1665,7 +1664,7 @@ def _getitem_tuple(self, tup):
except:
pass

retval = self.obj
retval = self.obj.copy()
axis = 0
for i, key in enumerate(tup):
if i >= self.obj.ndim:
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,5 @@ 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: 2 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,5 @@ 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

0 comments on commit 5daffa8

Please sign in to comment.