Skip to content

DOC: "Copy On Write: Patterns to avoid" confusion #56622

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

Closed
1 task done
avm19 opened this issue Dec 26, 2023 · 2 comments · Fixed by #56636
Closed
1 task done

DOC: "Copy On Write: Patterns to avoid" confusion #56622

avm19 opened this issue Dec 26, 2023 · 2 comments · Fixed by #56636

Comments

@avm19
Copy link
Contributor

avm19 commented Dec 26, 2023

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html#patterns-to-avoid

Documentation problem

This code snippet

In [59]: df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
In [60]: df2 = df.reset_index()
In [61]: df2.iloc[0, 0] = 100

is intended to illustrate that a copy (on write) will be created, because df and df2 reference the same data. In reality, no copy will be created because df2.iloc[0, 0] refers to the newly created integer column storing the reset index, which exists for df2, but not for df.

Suggested fix for documentation

Replace the last line of the snippet,

In [61]: df2.iloc[0, 0] = 100

with:

In [61]: df2.iloc[0, 1] = 100
@avm19 avm19 added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 26, 2023
@avm19 avm19 changed the title DOC: "Patterns to avoid" confusion DOC: "Copy On Write: Patterns to avoid" confusion Dec 26, 2023
@rhshadrach
Copy link
Member

cc @phofl

@rhshadrach rhshadrach added Copy / view semantics and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 26, 2023
@phofl
Copy link
Member

phofl commented Dec 27, 2023

Thx, very good catch

@phofl phofl added this to the 2.2 milestone Dec 27, 2023
@phofl phofl mentioned this issue Dec 27, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants