Skip to content

BUG: This fixes #55009 (raw=True caused apply method of DataFrame to ignore passed arguments) #55089

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 9 commits into from
Sep 13, 2023
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ 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 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
^^^^^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
wrap_function(self.func),
self.axis,
self.values,
*self.args,
**self.kwargs,
)

# TODO: mixed type case
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 @@ -45,8 +45,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