From 3584b52a7168ba7609d9b8f4a577e3f46a544d99 Mon Sep 17 00:00:00 2001 From: alonme Date: Thu, 30 Apr 2020 08:54:06 +0300 Subject: [PATCH] Fix Dataframe.apply documentation to include note regarding calling function twice on first element --- pandas/core/frame.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f8cb99e2b2e75..c34f4e2cd3709 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7204,6 +7204,14 @@ def apply(self, func, axis=0, raw=False, result_type=None, args=(), **kwds): DataFrame.aggregate: Only perform aggregating type operations. DataFrame.transform: Only perform transforming type operations. + Notes + ----- + In the current implementation apply calls `func` twice on the + first column/row to decide whether it can take a fast or slow + code path. This can lead to unexpected behavior if `func` has + side-effects, as they will take effect twice for the first + column/row. + Examples -------- >>> df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])