xref #8466
Can't it just return the freq
for you instead of raising an error? Helps with duck typing.
[~/]
[1]: pd.version.version
[1]: '0.13.1-434-gdcbbc59'
[2]: pd.tseries.frequencies.infer_freq(pd.PeriodIndex(['2000-01-01'], freq='D'))
Error message
File "/home/skipper/src/pandas-skipper/pandas/tseries/frequencies.py", line 656, in infer_freq
raise TypeError("PeriodIndex given. Check the `freq` attribute "
TypeError: PeriodIndex given. Check the `freq` attribute instead of using infer_freq.
Comment From: jtratner
I agree, seems weird at a surface level. That said, turns out you added this in with 32766d62 and initially raised the issue #5841 for it. Looks like there can be some strangeness with multiple periods in a periodindex or something? I'm not totally clear.
Comment From: jseabold
Ah, well that was before I realized that freq
/freqstr
doesn't consistently meet all of my needs. Now I'm using infer_freq
everywhere. Cf. #6637. Is it just my misunderstandings or does this all seems overly complicated? Convenience vs. "optimized" code. I'm not sure all those milliseconds I have saved are bigger than the time I've spent on these things.
Multiple periods in a PeriodIndex? Doesn't that defeat the whole purpose?
Comment From: jreback
the issue is that if you have a list of periods and you want to construct a Periodindex then in theory you should infer a new freq (eg say u string together 4 month periods that are quarterly)
I think this is pretty ambiguous and that is the issue (while time stamps can be too it is less so)
that said u can simply make sure that all the periods are the same freq and just return it
Comment From: jseabold
I see. I never even thought of this. I always assume that PeriodIndex is an index of consecutive (missing values allowed) Period types with the frequency correctly defined i.e., you never get monthly periods to represent a quarterly index. If we're given a PeriodIndex of monthly Periods that are supposed to be quarterly, then we (statsmodels) are going to incorrectly extrapolate out of sample.
The ambiguity is that it's not clear whether you should return monthly or quarterly? I'd argue to return quarterly. The use case being, I want to extrapolate out of sample. The offset should be (inferred to be) quarterly not monthly.
It makes sense to me not to allow a difference between frequency and offset in PeriodIndex
. PeriodIndex
should be the simple beast and DatetimeIndex
the more general where weirdness is allowed and frequency inference fails no? Maybe people are (ab)using PeriodIndex in that way, but I don't think you should let them. Anarchy!
Comment From: jbrockmendel
Closing in favor of #47227