FIX: resample to single group with custom function by Komnomnomnom · Pull Request #4494 · pandas-dev/pandas (original) (raw)
Using master code, when re-sampling to a frequency that would result in a single group the use of custom aggregation functions do not work as expected. The included changes fix this, and should fix #3849 too.
In [17]: import pandas as pd
In [18]: import numpy as np
In [19]: mysum = lambda x: x.sum()
In [20]: rng = pd.date_range('2000-1-1', '2000-1-10', freq='D')
In [21]: ts = pd.Series(np.random.randn(len(rng)), index=rng)
In [22]: ts.resample('M', how='sum') Out[22]: 2000-01-31 0.985236 Freq: M, dtype: float64
In [23]: ts.resample('M', how=mysum) Out[23]: 2000-01-31 0 Freq: M, dtype: float64