Skip to content

Commit b2b1c53

Browse files
authored
REGR: Passing args/kwargs to Series.agg fails (#43709)
1 parent 36d5c9b commit b2b1c53

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

doc/source/whatsnew/v1.3.4.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Fixed regressions
2020
- Fixed regression in :meth:`Series.cat.reorder_categories` failing to update the categories on the ``Series`` (:issue:`43232`)
2121
- Fixed regression in :meth:`Series.cat.categories` setter failing to update the categories on the ``Series`` (:issue:`43334`)
2222
- Fixed regression in :meth:`pandas.read_csv` raising ``UnicodeDecodeError`` exception when ``memory_map=True`` (:issue:`43540`)
23-
-
23+
- Fixed regression in :meth:`Series.aggregate` attempting to pass ``args`` and ``kwargs`` multiple times to the user supplied ``func`` in certain cases (:issue:`43357`)
2424

2525
.. ---------------------------------------------------------------------------
2626
@@ -29,6 +29,7 @@ Fixed regressions
2929
Bug fixes
3030
~~~~~~~~~
3131
- Fixed bug in :meth:`.GroupBy.mean` with datetimelike values including ``NaT`` values returning incorrect results (:issue:`43132`)
32+
- Fixed bug in :meth:`Series.aggregate` not passing the first ``args`` to the user supplied ``func`` in certain cases (:issue:`43357`)
3233

3334
.. ---------------------------------------------------------------------------
3435

pandas/core/apply.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,6 @@ def agg(self):
10511051
result = super().agg()
10521052
if result is None:
10531053
f = self.f
1054-
args = self.args
10551054
kwargs = self.kwargs
10561055

10571056
# string, list-like, and dict-like are entirely handled in super
@@ -1070,9 +1069,9 @@ def agg(self):
10701069
# then .agg and .apply would have different semantics if the
10711070
# operation is actually defined on the Series, e.g. str
10721071
try:
1073-
result = self.obj.apply(f, *args, **kwargs)
1072+
result = self.obj.apply(f)
10741073
except (ValueError, AttributeError, TypeError):
1075-
result = f(self.obj, *args, **kwargs)
1074+
result = f(self.obj)
10761075

10771076
return result
10781077

pandas/tests/apply/test_series_apply.py

+15
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ def test_apply_args():
9292
assert isinstance(result[0], list)
9393

9494

95+
@pytest.mark.parametrize(
96+
"args, kwargs, increment",
97+
[((), {}, 0), ((), {"a": 1}, 1), ((2, 3), {}, 32), ((1,), {"c": 2}, 201)],
98+
)
99+
def test_agg_args(args, kwargs, increment):
100+
# GH 43357
101+
def f(x, a=0, b=0, c=0):
102+
return x + a + 10 * b + 100 * c
103+
104+
s = Series([1, 2])
105+
result = s.agg(f, 0, *args, **kwargs)
106+
expected = s + increment
107+
tm.assert_series_equal(result, expected)
108+
109+
95110
def test_series_map_box_timestamps():
96111
# GH#2689, GH#2627
97112
ser = Series(pd.date_range("1/1/2000", periods=10))

0 commit comments

Comments
 (0)