Skip to content

BUG: base argument ignored in PeriodIndex resample #23882

Closed
@ms7463

Description

@ms7463

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions