Skip to content
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

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

Merged
merged 13 commits into from
Jun 14, 2017
Merged
Next Next commit
BUG: .iloc[:] and .loc[:] return copy of original object (#13873)
  • Loading branch information
margaret committed Jun 14, 2017
commit f8c22025d2273e35a0f8d5e3677968b4191eb97c
6 changes: 3 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
obj = self.obj

if not need_slice(slice_obj):
return obj
return obj.copy()
indexer = self._convert_slice_indexer(slice_obj, axis)

if isinstance(indexer, slice):
Expand Down Expand Up @@ -1349,7 +1349,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
""" this is pretty simple as we just have to deal with labels """
obj = self.obj
if not need_slice(slice_obj):
return obj
return obj.copy()

labels = obj._get_axis(axis)
indexer = labels.slice_indexer(slice_obj.start, slice_obj.stop,
Expand Down Expand Up @@ -1690,7 +1690,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
obj = self.obj

if not need_slice(slice_obj):
return obj
return obj.copy()

slice_obj = self._convert_slice_indexer(slice_obj, axis)
if isinstance(slice_obj, slice):
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,8 @@ def test_iloc_empty_list_indexer_is_ok(self):
tm.assert_frame_equal(df.iloc[[]], df.iloc[:0, :],
check_index_type=True,
check_column_type=True)

def test_loc_identity_slice_returns_new_object(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just rename to test_identity_slice_returns_new_object (and same for one in the test_loc file

# GH13873
df = DataFrame({'a': [1, 3, 5], 'b': [2, 4, 6]})
assert not df.iloc[:] is df
5 changes: 5 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,8 @@ def test_loc_empty_list_indexer_is_ok(self):
tm.assert_frame_equal(df.loc[[]], df.iloc[:0, :],
check_index_type=True,
check_column_type=True)

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