Skip to content

Fix for 55753 BUG: No kwargs in df.apply(raw=True) [ Backport to 2.1.x ] #55930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down