diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index d5ef047ef9d8a7..658adf5a943c9b 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -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') @@ -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): @@ -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: diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index 9f647819438fa1..70c7f673adf84d 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -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 diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 4c7250707da863..d86cf1fbc5520d 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -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