From 1970f9ec5f94ecd0f117f2b6b0c776f6593a2701 Mon Sep 17 00:00:00 2001 From: pranavkp71 Date: Sat, 20 Sep 2025 20:06:02 +0530 Subject: [PATCH 1/3] DOC: Warn about dtype inference with raw=True in DataFrame.apply --- pandas/core/frame.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f61e231736e31..c1b475658a24a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10554,6 +10554,13 @@ def apply( If you are just applying a NumPy reduction function this will achieve much better performance. + .. warning:: + + When ``raw=True``, the output dtype is inferred from the + **first returned value**. If that value is not ``None``but + later calls return ``Nonw``, a ``TypeError`` may be raised + because Numpy infers a non-nullable dtype. + result_type : {'expand', 'reduce', 'broadcast', None}, default None These only act when ``axis=1`` (columns): From 2c06f64f0dfb3fdfc9bd609da81f235b9234aa00 Mon Sep 17 00:00:00 2001 From: pranavkp71 Date: Sat, 20 Sep 2025 20:42:34 +0530 Subject: [PATCH 2/3] DOC: fix pre-commit lint issues in apply docstring --- pandas/core/frame.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c1b475658a24a..d405c5f9fde50 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10554,12 +10554,12 @@ def apply( If you are just applying a NumPy reduction function this will achieve much better performance. - .. warning:: + .. warning:: - When ``raw=True``, the output dtype is inferred from the - **first returned value**. If that value is not ``None``but - later calls return ``Nonw``, a ``TypeError`` may be raised - because Numpy infers a non-nullable dtype. + When ``raw=True``, the result dtype is inferred from the **first** + returned value. If that value is not ``None`` but later calls return + ``None``, a ``TypeError`` may occur because NumPy infers a + non-nullable dtype. result_type : {'expand', 'reduce', 'broadcast', None}, default None These only act when ``axis=1`` (columns): From 85f4628825e37c6018c90042265987a577cfa70c Mon Sep 17 00:00:00 2001 From: PRANAV Date: Wed, 8 Oct 2025 16:42:09 +0530 Subject: [PATCH 3/3] DOC: simplify dtype inference note in DataFrame.apply Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/core/frame.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d405c5f9fde50..2cb33f8b78bb9 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10557,9 +10557,7 @@ def apply( .. warning:: When ``raw=True``, the result dtype is inferred from the **first** - returned value. If that value is not ``None`` but later calls return - ``None``, a ``TypeError`` may occur because NumPy infers a - non-nullable dtype. + returned value. result_type : {'expand', 'reduce', 'broadcast', None}, default None These only act when ``axis=1`` (columns):