Skip to content

BUG: base argument ignored in PeriodIndex resample #23882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ms7463 opened this issue Nov 24, 2018 · 2 comments · Fixed by #23941
Closed

BUG: base argument ignored in PeriodIndex resample #23882

ms7463 opened this issue Nov 24, 2018 · 2 comments · Fixed by #23941
Labels
Bug Datetime Datetime data dtype Resample resample method
Milestone

Comments

@ms7463
Copy link
Contributor

ms7463 commented Nov 24, 2018

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

@gfyoung gfyoung added Datetime Datetime data dtype Resample resample method labels Nov 26, 2018
@gfyoung
Copy link
Member

gfyoung commented Nov 26, 2018

That seems reasonable. A PR would be good here.

@ms7463
Copy link
Contributor Author

ms7463 commented Nov 28, 2018

@gfyoung - added a PR - #23941 to resolve this issue.

@jreback jreback added this to the Contributions Welcome milestone Dec 4, 2018
@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants