Skip to content

Commit e17b1ff

Browse files
martin-sichomroeschkepre-commit-ci[bot]
authored andcommitted
BUG: This fixes pandas-dev#55009 (raw=True caused apply method of DataFrame to ignore passed arguments) (pandas-dev#55089)
* fixes pandas-dev#55009 * update documentation * write documentation * add test * change formatting * cite DataDrame directly in docs Co-authored-by: Matthew Roeschke <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Matthew Roeschke <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6ceaa61 commit e17b1ff

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

doc/source/whatsnew/v2.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Bug fixes
189189
~~~~~~~~~
190190
- Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`)
191191
- 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`)
192-
- Bug in :class:`pandas.io.parsers.ArrowParserWrapper` where ``usecols`` wasn't working when using pyarrow to read a csv with no headers (:issue:`54459`)
192+
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`)
193193

194194
Categorical
195195
^^^^^^^^^^^

pandas/core/apply.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,11 @@ def wrapper(*args, **kwargs):
955955
result = np.squeeze(result)
956956
else:
957957
result = np.apply_along_axis(
958-
wrap_function(self.func), self.axis, self.values
958+
wrap_function(self.func),
959+
self.axis,
960+
self.values,
961+
*self.args,
962+
**self.kwargs,
959963
)
960964

961965
# TODO: mixed type case

pandas/tests/apply/test_frame_apply.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ def test_apply(float_frame):
4545

4646

4747
@pytest.mark.parametrize("axis", [0, 1])
48-
def test_apply_args(float_frame, axis):
49-
result = float_frame.apply(lambda x, y: x + y, axis, args=(1,))
48+
@pytest.mark.parametrize("raw", [True, False])
49+
def test_apply_args(float_frame, axis, raw):
50+
result = float_frame.apply(lambda x, y: x + y, axis, args=(1,), raw=raw)
5051
expected = float_frame + 1
5152
tm.assert_frame_equal(result, expected)
5253

0 commit comments

Comments
 (0)