diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 8fde5df6fd75a..0e6c98a1a8d23 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -291,4 +291,4 @@ Bug Fixes - Bug in ``to_sql`` taking the boolean column as text column (:issue:`7678`) - Bug in grouped `hist` doesn't handle `rot` kw and `sharex` kw properly (:issue:`7234`) - +- Bug (regression) in ``PeriodIndex`` constructor when passed ``Series`` objects (:issue:`7701`). diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py index cceac61f392a8..ed56bdc827ede 100644 --- a/pandas/tseries/period.py +++ b/pandas/tseries/period.py @@ -14,7 +14,7 @@ import pandas.core.common as com from pandas.core.common import (isnull, _INT64_DTYPE, _maybe_box, - _values_from_object) + _values_from_object, ABCSeries) from pandas import compat from pandas.lib import Timestamp import pandas.lib as lib @@ -1261,13 +1261,13 @@ def _range_from_fields(year=None, month=None, quarter=None, day=None, def _make_field_arrays(*fields): length = None for x in fields: - if isinstance(x, (list, np.ndarray)): + if isinstance(x, (list, np.ndarray, ABCSeries)): if length is not None and len(x) != length: raise ValueError('Mismatched Period array lengths') elif length is None: length = len(x) - arrays = [np.asarray(x) if isinstance(x, (np.ndarray, list)) + arrays = [np.asarray(x) if isinstance(x, (np.ndarray, list, ABCSeries)) else np.repeat(x, length) for x in fields] return arrays diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index 42edb799b4c89..53375b4d07796 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -1281,6 +1281,15 @@ def test_constructor_nat(self): self.assertRaises( ValueError, period_range, start='2011-01-01', end='NaT', freq='M') + def test_constructor_year_and_quarter(self): + year = pd.Series([2001, 2002, 2003]) + quarter = year - 2000 + idx = PeriodIndex(year=year, quarter=quarter) + strs = ['%dQ%d' % t for t in zip(quarter, year)] + lops = list(map(Period, strs)) + p = PeriodIndex(lops) + tm.assert_index_equal(p, idx) + def test_is_(self): create_index = lambda: PeriodIndex(freq='A', start='1/1/2001', end='12/1/2009')