From ea9a372a01250994f5446c8b6c7b1b193b7fd620 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Tue, 16 Feb 2021 17:10:16 -0500 Subject: [PATCH] DOC: Add list of UDF methods to mutation gotcha --- doc/source/user_guide/gotchas.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/user_guide/gotchas.rst b/doc/source/user_guide/gotchas.rst index 4089f9523724f..180f833a2753d 100644 --- a/doc/source/user_guide/gotchas.rst +++ b/doc/source/user_guide/gotchas.rst @@ -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: @@ -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 ---------------------------------------------------------