Skip to content

Commit 31d552d

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

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.23.5.txt

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ def aggregate(self, arg, *args, **kwargs):
239239
self._set_binner()
240240
result, how = self._aggregate(arg, *args, **kwargs)
241241
if result is None:
242+
grouper = kwargs.get('grouper', None)
242243
result = self._groupby_and_aggregate(arg,
244+
grouper,
243245
*args,
244246
**kwargs)
245247

@@ -852,7 +854,7 @@ def __init__(self, obj, *args, **kwargs):
852854
self._groupby.grouper.mutated = True
853855
self.groupby = copy.copy(parent.groupby)
854856

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

pandas/tests/test_resample.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,14 @@ 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)
2171+
2172+
result = self.series.resample('D').apply(f, 10)
2173+
expected = self.series.resample('D').mean()
2174+
tm.assert_series_equal(result, expected)
2175+
21682176

21692177
class TestPeriodIndex(Base):
21702178
_index_factory = lambda x: period_range

0 commit comments

Comments
 (0)