Skip to content

Commit 553a68e

Browse files
committed
Fixed additional passing args to resample().apply
1 parent 4f11d1a commit 553a68e

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ Groupby/Resample/Rolling
693693
``SeriesGroupBy`` when the grouping variable only contains NaNs and numpy version < 1.13 (:issue:`21956`).
694694
- Multiple bugs in :func:`pandas.core.Rolling.min` with ``closed='left'` and a
695695
datetime-like index leading to incorrect results and also segfault. (:issue:`21704`)
696-
-
696+
- Bug in :meth:`Resampler.apply` when passing postiional arguments to applied func (:issue:`14615`).
697697

698698
Sparse
699699
^^^^^^

pandas/core/resample.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,15 @@ def pipe(self, func, *args, **kwargs):
234234
klass='DataFrame',
235235
versionadded='',
236236
axis=''))
237-
def aggregate(self, arg, *args, **kwargs):
237+
def aggregate(self, func, *args, **kwargs):
238238

239239
self._set_binner()
240-
result, how = self._aggregate(arg, *args, **kwargs)
240+
result, how = self._aggregate(func, *args, **kwargs)
241241
if result is None:
242-
result = self._groupby_and_aggregate(arg,
242+
how = func
243+
grouper = None
244+
result = self._groupby_and_aggregate(how,
245+
grouper,
243246
*args,
244247
**kwargs)
245248

@@ -852,7 +855,7 @@ def __init__(self, obj, *args, **kwargs):
852855
self._groupby.grouper.mutated = True
853856
self.groupby = copy.copy(parent.groupby)
854857

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

pandas/tests/test_resample.py

+14
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,20 @@ 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+
2177+
# Testing as kwarg
2178+
result = self.series.resample('D').apply(f, add_arg=multiplier)
2179+
expected = self.series.resample('D').mean().multiply(multiplier)
2180+
tm.assert_series_equal(result, expected)
2181+
21682182

21692183
class TestPeriodIndex(Base):
21702184
_index_factory = lambda x: period_range

0 commit comments

Comments
 (0)