Skip to content

Commit 7c4f6bc

Browse files
author
luke
committed
fix merge conflict
1 parent 384a603 commit 7c4f6bc

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

doc/source/whatsnew/v1.5.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Bug fixes
3333
- Bug when chaining several :meth:`.Styler.concat` calls, only the last styler was concatenated (:issue:`49207`)
3434
- Fixed bug when instantiating a :class:`DataFrame` subclass inheriting from ``typing.Generic`` that triggered a ``UserWarning`` on python 3.11 (:issue:`49649`)
3535
- Bug in :func:`pandas.testing.assert_series_equal` (and equivalent ``assert_`` functions) when having nested data and using numpy >= 1.25 (:issue:`50360`)
36+
- Fixed bug when :meth:`DataFrame.agg` receives single-element function list given args and kwargs (:issue:`50624`)
3637
-
3738

3839
.. ---------------------------------------------------------------------------

pandas/core/apply.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ def __init__(
130130
def f(x):
131131
return func(x, *args, **kwargs)
132132

133+
# GH 50624
134+
elif (
135+
(args or kwargs)
136+
and not isinstance(func, str)
137+
and is_one_element_callable_list(func)
138+
):
139+
140+
def f(x):
141+
return func[0](x, *args, **kwargs)
142+
133143
else:
134144
f = func
135145

@@ -1206,6 +1216,11 @@ def is_multi_agg_with_relabel(**kwargs) -> bool:
12061216
)
12071217

12081218

1219+
def is_one_element_callable_list(func: AggFuncType | None) -> bool:
1220+
# GH 50624
1221+
return isinstance(func, list) and len(func) == 1
1222+
1223+
12091224
def normalize_keyword_aggregation(
12101225
kwargs: dict,
12111226
) -> tuple[dict, list[str], npt.NDArray[np.intp]]:

pandas/tests/apply/test_frame_apply_relabeling.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ def test_agg_namedtuple():
9595
index=pd.Index(["foo", "bar", "cat"]),
9696
)
9797
tm.assert_frame_equal(result, expected)
98+
99+
100+
def test_agg_given_one_element_func_list_arg_kwargs():
101+
# GH 50624
102+
df = pd.DataFrame({"x": [1, 2, 3]})
103+
104+
def foo(x, a, b=2):
105+
return x + a + b
106+
107+
result = df.agg([foo], 0, 1, b=2)
108+
expected = pd.DataFrame({"x": [4, 5, 6]})
109+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)