From ffb47fef323c13361a959bf43f4894792547b088 Mon Sep 17 00:00:00 2001 From: Daniel Isaac Date: Mon, 13 Nov 2023 01:26:35 +0530 Subject: [PATCH 1/3] Fix for 55753 BUG: No kwargs in df.apply(raw=True) [ Backport to 2.1.x ] --- 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 e5683359c2fb9..43bc26f6eb637 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -923,7 +923,9 @@ 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 cea63fa89a74c816c4576cfd163f245e3cdbf394 Mon Sep 17 00:00:00 2001 From: Daniel Isaac Date: Mon, 13 Nov 2023 01:27:06 +0530 Subject: [PATCH 2/3] Fix for 55753 BUG: No kwargs in df.apply(raw=True) [ Backport to 2.1.x ] --- 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 49a82c39b6a42f23c784e16308b7dc84db200858 Mon Sep 17 00:00:00 2001 From: dannyi96 Date: Tue, 14 Nov 2023 17:18:00 +0530 Subject: [PATCH 3/3] review comment - updated whatsnew --- doc/source/whatsnew/v2.1.4.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.4.rst b/doc/source/whatsnew/v2.1.4.rst index 04bbb0f806cbd..d61714d9473c6 100644 --- a/doc/source/whatsnew/v2.1.4.rst +++ b/doc/source/whatsnew/v2.1.4.rst @@ -21,7 +21,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ -- +- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`) - .. ---------------------------------------------------------------------------