Skip to content

Commit a06f264

Browse files
committed
Fixed additional passing args to resample().apply
1 parent 475e391 commit a06f264

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.23.5.txt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Bug Fixes
3434
**Groupby/Resample/Rolling**
3535

3636
- Bug in :meth:`DataFrame.resample` when resampling ``NaT`` in ``TimeDeltaIndex`` (:issue:`13223`).
37+
- Bug in :meth:`Resampler.apply` when passing an additional argument to applied func (:issue:`14615`).
3738
-
3839

3940
**Missing**

pandas/core/resample.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def aggregate(self, arg, *args, **kwargs):
240240
result, how = self._aggregate(arg, *args, **kwargs)
241241
if result is None:
242242
result = self._groupby_and_aggregate(arg,
243+
None,
243244
*args,
244245
**kwargs)
245246

@@ -852,7 +853,7 @@ def __init__(self, obj, *args, **kwargs):
852853
self._groupby.grouper.mutated = True
853854
self.groupby = copy.copy(parent.groupby)
854855

855-
def _apply(self, f, **kwargs):
856+
def _apply(self, f, *args, **kwargs):
856857
"""
857858
dispatch to _upsample; we are stripping all of the _upsample kwargs and
858859
performing the original function call on the grouped object

pandas/tests/test_resample.py

+9
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,15 @@ def test_resample_datetime_values(self):
21652165
res = df['timestamp'].resample('2D').first()
21662166
tm.assert_series_equal(res, exp)
21672167

2168+
def test_resample_apply_with_additional_args(self):
2169+
def f(data, add_arg):
2170+
return np.mean(data) * add_arg
2171+
2172+
multiplier = 10
2173+
result = self.series.resample('D').apply(f, multiplier)
2174+
expected = self.series.resample('D').mean().multiply(multiplier)
2175+
tm.assert_series_equal(result, expected)
2176+
21682177

21692178
class TestPeriodIndex(Base):
21702179
_index_factory = lambda x: period_range

0 commit comments

Comments
 (0)