BUG: base argument ignored in PeriodIndex resample · Issue #23882 · pandas-dev/pandas (original) (raw)
Code Sample
df = pd.DataFrame(np.random.randn(100, 10), index=pd.period_range('19700101', periods=100, freq='H')) period_resample_with_base = df.resample('24H', base=10).mean().to_timestamp() ts_resample_with_base = df.to_timestamp().resample('24H', base=10).mean() ts_resample_no_base = df.to_timestamp().resample('24H').mean()
period_resample_with_base.to_timestamp().equals(ts_resample_with_base) # -> False, should be True period_resample_with_base.to_timestamp().equals(ts_resample_no_base) # -> True, should be False
Problem description
The base argument is ignored when resampling with PeriodIndex. It seems that the problem lies in pandas.core.resample.TimeGrouper._get_period_bins
, where the base option should be applied (as it is in _get_time_bins
) to get the start and end of the grouped interval.
At the very least providing the base argument to PeriodIndex resample should raise an exception.
Output of pd.show_versions()
v0.24.0-dev