Skip to content
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

BUG: base argument ignored in PeriodIndex resample #23882

Closed
ArtinSarraf opened this issue Nov 24, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@ArtinSarraf
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented Nov 26, 2018

That seems reasonable. A PR would be good here.

@ArtinSarraf

This comment has been minimized.

Copy link
Contributor Author

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
You can’t perform that action at this time.