Skip to content

Commit 19bbe06

Browse files
authored
Fix for 55753 BUG: No kwargs in df.apply(raw=True) [ Backport to 2.1.x ] (#55930)
* Fix for 55753 BUG: No kwargs in df.apply(raw=True) [ Backport to 2.1.x ] * Fix for 55753 BUG: No kwargs in df.apply(raw=True) [ Backport to 2.1.x ] * review comment - updated whatsnew
1 parent 486c723 commit 19bbe06

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

doc/source/whatsnew/v2.1.4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Fixed regressions
2121

2222
Bug fixes
2323
~~~~~~~~~
24-
-
24+
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`)
2525
-
2626

2727
.. ---------------------------------------------------------------------------

pandas/core/apply.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,9 @@ def wrapper(*args, **kwargs):
923923

924924
return wrapper
925925

926-
result = np.apply_along_axis(wrap_function(self.func), self.axis, self.values)
926+
result = np.apply_along_axis(
927+
wrap_function(self.func), self.axis, self.values, *self.args, **self.kwargs
928+
)
927929

928930
# TODO: mixed type case
929931
if result.ndim == 2:

pandas/tests/apply/test_frame_apply.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def test_apply(float_frame):
3838

3939

4040
@pytest.mark.parametrize("axis", [0, 1])
41-
def test_apply_args(float_frame, axis):
42-
result = float_frame.apply(lambda x, y: x + y, axis, args=(1,))
41+
@pytest.mark.parametrize("raw", [True, False])
42+
def test_apply_args(float_frame, axis, raw):
43+
result = float_frame.apply(lambda x, y: x + y, axis, args=(1,), raw=raw)
4344
expected = float_frame + 1
4445
tm.assert_frame_equal(result, expected)
4546

0 commit comments

Comments
 (0)