Skip to content

DOC: Add list of UDF methods to mutation gotcha #39851

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 1 commit into from
Feb 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/source/user_guide/gotchas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ testing for membership in the list of column names.
Mutating with User Defined Function (UDF) methods
-------------------------------------------------

This section applies to pandas methods that take a UDF. In particular, the methods
``.apply``, ``.aggregate``, ``.transform``, and ``.filter``.

It is a general rule in programming that one should not mutate a container
while it is being iterated over. Mutation will invalidate the iterator,
causing unexpected behavior. Consider the example:
Expand Down Expand Up @@ -246,7 +249,6 @@ not apply to the container being iterated over.
df = pd.DataFrame({"a": [1, 2, 3], 'b': [4, 5, 6]})
df.apply(f, axis="columns")


``NaN``, Integer ``NA`` values and ``NA`` type promotions
---------------------------------------------------------

Expand Down