From fd348ae9ca10f3030cbadb6be57ec555ad8d577a Mon Sep 17 00:00:00 2001 From: Diogo Pereira Date: Sun, 5 Oct 2014 06:01:40 +0100 Subject: [PATCH] Let PeriodIndex infer frequency by converting first element to Period --- pandas/tseries/period.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py index b4d8a6547950d..6fde54a3eeb9b 100644 --- a/pandas/tseries/period.py +++ b/pandas/tseries/period.py @@ -683,6 +683,11 @@ def _from_arraylike(cls, data, freq, tz): if freq is None and len(data) > 0: freq = getattr(data[0], 'freq', None) + if freq is None: + try: + freq = getattr(Period(data[0]), 'freq', None) + except Exception: + pass if freq is None: raise ValueError('freq not specified and cannot be ' @@ -702,6 +707,11 @@ def _from_arraylike(cls, data, freq, tz): else: if freq is None and len(data) > 0: freq = getattr(data[0], 'freq', None) + if freq is None: + try: + freq = getattr(Period(data[0]), 'freq', None) + except Exception: + pass if freq is None: raise ValueError('freq not specified and cannot be '