Skip to content

API: make 'freq' mean the same thing for PeriodIndex as DTI/TDI #47227

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

Open
jbrockmendel opened this issue Jun 4, 2022 · 4 comments
Open

API: make 'freq' mean the same thing for PeriodIndex as DTI/TDI #47227

jbrockmendel opened this issue Jun 4, 2022 · 4 comments
Labels
API - Consistency Internal Consistency of API/Behavior API Design Period Period data type

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Jun 4, 2022

ATM PeriodIndex.freq tells us about the index's dtype, while DatetimeIndex.freq tells us about the difference between any two consecutive elements.

Changing PeriodIndex.freq would let us share more code.

update If we do this, we should also deprecate PeriodIndex.is_full, which seems to be a kludge for checking if the index is freq-like in the DTI sense

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 4, 2022
@simonjayhawkins simonjayhawkins added API Design Period Period data type API - Consistency Internal Consistency of API/Behavior and removed Bug labels Jun 4, 2022
@simonjayhawkins
Copy link
Member

p = period_range("2022", periods=9, freq="M")
print(p.freq)
print(p[::3].freq)
<MonthEnd>
<MonthEnd>

p[::3].freq would be <3 * MonthEnds>?

we would also not raise in infer_freq and return the frequency of the Index, xref #6771

@jbrockmendel
Copy link
Member Author

That's what i have in mind, yes.

@simonjayhawkins
Copy link
Member

So would also add the freq to the PeriodIndex repr?

PeriodIndex(['2022-01', '2022-02', '2022-03', '2022-04', '2022-05', '2022-06',
             '2022-07', '2022-08', '2022-09'],
            dtype='period[M]', freq='M')

and for p[::3]

PeriodIndex(['2022-01', '2022-04', '2022-07'], dtype='period[M]', freq='3M')

@simonjayhawkins simonjayhawkins removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jun 6, 2022
@jbrockmendel
Copy link
Member Author

Looking at what this might take, I think for consistency if we deprecate PeriodIndex.freq we'd probably need to do the same for Period.freq, which would in turn likely require deprecating freq in the Period constructor. That's pretty invasive and I don't have any good ideas for what to call it instead. "date_offset" is accurate but not that informative.

Another option would be to deprecate 'freq' on DTI/TDI and rename it to something else, though again i don't have a good idea of what that something else would be. "interval" came to mind but that would be confusing with pd.Interval.

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 API Design Period Period data type
Projects
None yet
Development

No branches or pull requests

2 participants