Skip to content

PeriodIndex cannot infer frequency in cases where Period can #8466

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
diogocp opened this issue Oct 5, 2014 · 4 comments
Closed

PeriodIndex cannot infer frequency in cases where Period can #8466

diogocp opened this issue Oct 5, 2014 · 4 comments
Labels
Enhancement Frequency DateOffsets Period Period data type

Comments

@diogocp
Copy link

diogocp commented Oct 5, 2014

xref #6771

Period("2000-01")
Period('2000-01', 'M')

PeriodIndex(["2000-01"])
ValueError: freq not specified and cannot be inferred from first element

Same problem with 2000-Jan and Jan-2000. Works fine if I pass freq="M".

@jreback
Copy link
Contributor

jreback commented Oct 5, 2014

you need st least. 3 element to infer a freq
eg is. 2000-01, M, Q, yearly, daily or what
Period is just defaulting to the periodicity of the passed value

@diogocp
Copy link
Author

diogocp commented Oct 5, 2014

you need st least. 3 element to infer a freq

I get the same error with PeriodIndex(["2000-01", "2000-02", "2000-03"]), or with a larger list.

Period is just defaulting to the periodicity of the passed value

That's sort of what I expected from PeriodIndex: try to use the inferred frequency (using the same algorithm as Period) of the first element of the data.

A simple workaround is PeriodIndex([Period(x) for x in ["2000-01", "2000-02"]]).

@jreback
Copy link
Contributor

jreback commented Oct 5, 2014

see #6771

most of these conversions are ambiguous (I suppose in the given case) its prob ok.

So welcome to provide a soln for a fully-functional infer_freq that can handle PeriodIndex. It cannot simply be on the 1st element. You have to do full subtractions, then it STILL may be ambiguous. Better to pass it to a DatetimeIndex, infer then convert back to a PeriodIndex.

So we'll keep this as an adjust issue. but soln is a bit non-trivial.

@jreback jreback added this to the 0.16 milestone Oct 5, 2014
@jreback jreback added the Period Period data type label Oct 5, 2014
@jreback jreback modified the milestones: 0.16, 0.15.1 Oct 7, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@TomAugspurger
Copy link
Contributor

You have to do full subtractions, then it STILL may be ambiguous.

This seems very fragile... I think we'll close this, unless someone can provide a clear example and proposed API.

@TomAugspurger TomAugspurger modified the milestones: Contributions Welcome, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Frequency DateOffsets Period Period data type
Projects
None yet
Development

No branches or pull requests

3 participants