From 8376620b54eda6d83c0f79142b8f14e6cb9d513a Mon Sep 17 00:00:00 2001 From: pranavkp71 Date: Sat, 20 Sep 2025 20:06:02 +0530 Subject: [PATCH 1/5] 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 643974db5f2bf..130859ce561e8 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10629,6 +10629,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 366b1d2f0fb047836ad0530232bc8b0d459a975d Mon Sep 17 00:00:00 2001 From: pranavkp71 Date: Sat, 20 Sep 2025 20:42:34 +0530 Subject: [PATCH 2/5] 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 130859ce561e8..8bb86432ac1ba 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10629,12 +10629,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 81471f85d7af42c27223a9313a2c4a6153072e7c Mon Sep 17 00:00:00 2001 From: PRANAV Date: Wed, 8 Oct 2025 16:42:09 +0530 Subject: [PATCH 3/5] 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 8bb86432ac1ba..6a000de1d069a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10632,9 +10632,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): From d52a3a188130e8efba11f8f420636ae12dd74df9 Mon Sep 17 00:00:00 2001 From: pranavkp71 Date: Mon, 13 Oct 2025 19:36:05 +0530 Subject: [PATCH 4/5] DOC: simplify dtype note in DataFrame.apply per review --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6a000de1d069a..1b9a6cfa80fec 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10629,7 +10629,7 @@ def apply( If you are just applying a NumPy reduction function this will achieve much better performance. - .. warning:: + .. note:: When ``raw=True``, the result dtype is inferred from the **first** returned value. From e202d8599a8d823d2bd3cfa23a230cad659785bd Mon Sep 17 00:00:00 2001 From: pranavkp71 Date: Tue, 14 Oct 2025 21:22:53 +0530 Subject: [PATCH 5/5] DOC: Fix indentation for raw=True note in DataFrame.apply docstring --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1b9a6cfa80fec..f97fbb83a69af 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10631,8 +10631,8 @@ def apply( .. note:: - When ``raw=True``, the result dtype is inferred from the **first** - returned value. + When ``raw=True``, the result dtype is inferred from the **first** + returned value. result_type : {'expand', 'reduce', 'broadcast', None}, default None These only act when ``axis=1`` (columns):