From bc87b6da70445c8fdb4c1007589559696eb6087d Mon Sep 17 00:00:00 2001 From: martin-sicho Date: Mon, 11 Sep 2023 11:51:38 +0200 Subject: [PATCH 1/7] fixes #55009 --- pandas/core/apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 26467a4a982fa..fd8c9dd292ae3 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -925,7 +925,7 @@ def wrapper(*args, **kwargs): return wrapper - result = np.apply_along_axis(wrap_function(self.func), self.axis, self.values) + result = np.apply_along_axis(wrap_function(self.func), self.axis, self.values, *self.args, **self.kwargs) # TODO: mixed type case if result.ndim == 2: From 0402112577d421841f5fe17a7baca51e25fadf34 Mon Sep 17 00:00:00 2001 From: martin-sicho Date: Mon, 11 Sep 2023 12:00:52 +0200 Subject: [PATCH 2/7] update documentation --- doc/source/whatsnew/v2.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index a795514aa31f8..a7f8378175358 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -168,6 +168,7 @@ Performance improvements Bug fixes ~~~~~~~~~ - Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`) +- Bug in :class:`pandas.core.window.Rolling` where passing ``raw=True`` caused ``apply`` method of ``DataFrame`` to ignore arguments passed to the applied function (:issue:`55009`) - Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`) Categorical From d283b48a477d35baeff332d414801f91202a5690 Mon Sep 17 00:00:00 2001 From: martin-sicho Date: Mon, 11 Sep 2023 12:00:52 +0200 Subject: [PATCH 3/7] write documentation --- doc/source/whatsnew/v2.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index a795514aa31f8..f20add70ac18e 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -168,6 +168,7 @@ Performance improvements Bug fixes ~~~~~~~~~ - Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`) +- Bug in :class:`pandas.core.apply.FrameApply` where passing ``raw=True`` caused ``apply`` method of ``DataFrame`` to ignore arguments passed to the applied function (:issue:`55009`) - Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`) Categorical From 449848843550cc148d9dcbf55ab4deb2197f162c Mon Sep 17 00:00:00 2001 From: martin-sicho Date: Mon, 11 Sep 2023 12:13:32 +0200 Subject: [PATCH 4/7] add test --- pandas/tests/apply/test_frame_apply.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 3a3f73a68374b..92612861e551a 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -38,8 +38,9 @@ def test_apply(float_frame): @pytest.mark.parametrize("axis", [0, 1]) -def test_apply_args(float_frame, axis): - result = float_frame.apply(lambda x, y: x + y, axis, args=(1,)) +@pytest.mark.parametrize("raw", [True, False]) +def test_apply_args(float_frame, axis, raw): + result = float_frame.apply(lambda x, y: x + y, axis, args=(1,), raw=raw) expected = float_frame + 1 tm.assert_frame_equal(result, expected) From c23b6be51e091e825f207dd71758742b35ba8752 Mon Sep 17 00:00:00 2001 From: martin-sicho Date: Mon, 11 Sep 2023 12:28:49 +0200 Subject: [PATCH 5/7] change formatting --- pandas/core/apply.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index fd8c9dd292ae3..4e20c77a17da5 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -925,7 +925,9 @@ def wrapper(*args, **kwargs): return wrapper - result = np.apply_along_axis(wrap_function(self.func), self.axis, self.values, *self.args, **self.kwargs) + result = np.apply_along_axis( + wrap_function(self.func), self.axis, self.values, *self.args, **self.kwargs + ) # TODO: mixed type case if result.ndim == 2: From e0b76f87ffd8719144206b2456c6809e8c40e73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0=C3=ADcho?= Date: Tue, 12 Sep 2023 13:01:15 +0200 Subject: [PATCH 6/7] cite DataDrame directly in docs Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/whatsnew/v2.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index f20add70ac18e..488381524dac4 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -168,7 +168,7 @@ Performance improvements Bug fixes ~~~~~~~~~ - Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`) -- Bug in :class:`pandas.core.apply.FrameApply` where passing ``raw=True`` caused ``apply`` method of ``DataFrame`` to ignore arguments passed to the applied function (:issue:`55009`) +- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) - Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`) Categorical From ecec8344fe1f1ac6c60fe765f372038726e641c5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 15:37:31 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/source/whatsnew/v2.2.0.rst | 2 +- pandas/core/apply.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index a951b7fbfe1c4..e640a091e09fb 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -170,8 +170,8 @@ Performance improvements Bug fixes ~~~~~~~~~ - Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`) -- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) - Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`) +- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) Categorical ^^^^^^^^^^^ diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 1e7d9524e77e2..9748d4fe66739 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -955,7 +955,11 @@ def wrapper(*args, **kwargs): result = np.squeeze(result) else: result = np.apply_along_axis( - wrap_function(self.func), self.axis, self.values, *self.args, **self.kwargs + wrap_function(self.func), + self.axis, + self.values, + *self.args, + **self.kwargs, ) # TODO: mixed type case