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

Missing Periods for some DateOffsets #5091

Open
cancan101 opened this issue Oct 2, 2013 · 4 comments
Open

Missing Periods for some DateOffsets #5091

cancan101 opened this issue Oct 2, 2013 · 4 comments
Labels
API - Consistency Internal Consistency of API/Behavior Bug Frequency DateOffsets Period Period data type

Comments

@cancan101
Copy link
Contributor

There are not corresponding Periods for many DateOffsets.

For example see how the freq changes:

ts = pd.date_range('1/1/2012', periods=4, freq=pd.offsets.BQuarterEnd())
per = ts.to_period()
ts_per = per.to_timestamp()

In [210]: ts
Out[210]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-03-30 00:00:00, ..., 2012-12-31 00:00:00]
Length: 4, Freq: BQ-MAR, Timezone: None

In [211]: per
Out[211]: 
<class 'pandas.tseries.period.PeriodIndex'>
freq: Q-DEC
[2012Q1, ..., 2012Q4]
length: 4

In [212]: ts_per
Out[212]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01 00:00:00, ..., 2012-10-01 00:00:00]
Length: 4, Freq: QS-OCT, Timezone: None

This issue is alluded to in comment: https://github.com/pydata/pandas/blob/master/pandas/tseries/frequencies.py#L329

@jreback jreback modified the milestones: 0.14.1, 0.14.0 Apr 28, 2014
@jreback jreback modified the milestones: 0.15.0, 0.14.1 Jun 10, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jbrockmendel
Copy link
Member

Running into this while testing out offsets. It looks like the frequencies that Period plays nicely with are hard-coded into period_helper.c. Implementing more of the standard-but-less-common offsets (much less custom offsets) would be a pretty big task, merits discussion as to whether its worth the effort.

@jbrockmendel jbrockmendel mentioned this issue Dec 19, 2017
39 tasks
@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed API Design Frequency DateOffsets Datetime Datetime data dtype labels Mar 31, 2020
@mroeschke mroeschke added Bug Frequency DateOffsets Period Period data type Datetime Datetime data dtype and removed Needs Tests Unit test(s) needed to prevent regressions good first issue labels Apr 1, 2020
@mroeschke mroeschke removed the Datetime Datetime data dtype label Apr 11, 2021
@simonjayhawkins
Copy link
Member

ts = pd.date_range("1/1/2012", periods=4, freq=pd.offsets.QuarterEnd())
print(ts)
per = ts.to_period()
print(per)
ts_per = per.to_timestamp()
print(ts_per)
DatetimeIndex(['2012-03-31', '2012-06-30', '2012-09-30', '2012-12-31'], dtype='datetime64[ns]', freq='Q-MAR')
PeriodIndex(['2012Q4', '2013Q1', '2013Q2', '2013Q3'], dtype='period[Q-MAR]')
DatetimeIndex(['2012-01-01', '2012-04-01', '2012-07-01', '2012-10-01'], dtype='datetime64[ns]', freq='QS-OCT')

with freq=pd.offsets.QuarterEnd() the conversion from DatetimeIndex to PeriodIndex seems fine, but does not roundtrip.

with freq=pd.offsets.BQuarterEnd() as in the OP in the code sample, the output now looks like (just cosmetic changes from when the issue was raised)

DatetimeIndex(['2012-03-30', '2012-06-29', '2012-09-28', '2012-12-31'], dtype='datetime64[ns]', freq='BQ-MAR')
PeriodIndex(['2012Q1', '2012Q2', '2012Q3', '2012Q4'], dtype='period[Q-DEC]')
DatetimeIndex(['2012-01-01', '2012-04-01', '2012-07-01', '2012-10-01'], dtype='datetime64[ns]', freq='QS-OCT')

This maybe related to #13871, that if these offsets are not accepted in the Period/PeriodIndex constructors, then maybe they should raise also in to_period() for consistency.

@simonjayhawkins simonjayhawkins added the API - Consistency Internal Consistency of API/Behavior label Jun 5, 2022
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@jbrockmendel jbrockmendel mentioned this issue May 29, 2023
3 tasks
@jbrockmendel
Copy link
Member

@natmokval did one of your recent DOC PRs address this?

@natmokval
Copy link
Contributor

@natmokval did one of your recent DOC PRs address this?

I think my PR #53477 might be related to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Bug Frequency DateOffsets Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants