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 @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,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