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".

Comment From: jreback

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

Comment From: diogocp

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"]]).

Comment From: jreback

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.

Comment From: TomAugspurger

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.