Skip to content

DOC: clarify "inplace"-ness of DataFrame.setitem #51300

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
jorisvandenbossche opened this issue Feb 10, 2023 · 3 comments · Fixed by #51328
Closed

DOC: clarify "inplace"-ness of DataFrame.setitem #51300

jorisvandenbossche opened this issue Feb 10, 2023 · 3 comments · Fixed by #51328
Assignees
Labels

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Feb 10, 2023

The docstring of DataFrame.isetitem (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.isetitem.html) has the following quote:

Unlike frame.iloc[:, i] = value, frame.isetitem(loc, value) will never try to set the values in place, but will always insert a new array.

But the docstring is actually confusing here, because it is an inplace method in the sense that it is updating the object inplace (and not returning a new object like most methods). It's only not inplace in the sense that it will not update values inplace.

Originally posted by @jorisvandenbossche in #51296 (comment)

@jorisvandenbossche
Copy link
Member Author

We should also fix the formatting in that docstring to properly show the inline code snippets as code.

@loicdiridollou
Copy link
Member

loicdiridollou commented Feb 11, 2023

I did a few experiments on my side to better understand the behavior and this is how we could rephrase it:

frame.isetimtem(loc, value) is an in-place method as it will modify the frame in place (not returning a new object) but it will not update the values of the column itself, it will instead insert a new array.

I will address the code snippets in the meantime. Let me know if you agree with the rephrasing above, I can make another proposal if needed.

@loicdiridollou
Copy link
Member

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants