Skip to content

TST: df.loc[:, 'col'] returning a view, but df.loc[df.index, 'col'] returning a copy #34996

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 16 commits into from
Jul 9, 2020
Merged
10 changes: 10 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ def test_loc_index(self):
result = df.loc[pd.array(mask, dtype="boolean")]
tm.assert_frame_equal(result, expected)

def test_loc_copy_vs_view(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I am almost sure we have other tests about this, can you check and co-locate

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes you're right. This one

def test_identity_slice_returns_new_object(self):

is very similar so moved it there

# GH 15631
x = DataFrame(zip(range(3), range(3)), columns=["a", "b"])

y = x.copy()
q = x.loc[:, "a"]
q += 2

tm.assert_frame_equal(x, y)

def test_loc_general(self):

df = DataFrame(
Expand Down