Skip to content

Commit

Permalink
BUG: .iloc[:] and .loc[:] return copy of original object (pandas-dev#…
Browse files Browse the repository at this point in the history
  • Loading branch information
margaret committed Jun 14, 2017
1 parent 2e24a8f commit f8c2202
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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):
# 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

0 comments on commit f8c2202

Please sign in to comment.