diff --git a/RELEASE.rst b/RELEASE.rst index 4a7c204db11a5..df8265b941abd 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -229,6 +229,7 @@ pandas 0.11.0 - fixed handling of rolling_corr with center=True which could produce corr>1 (GH3155_) - Fixed issues where indices can be passed as 'index/column' in addition to 0/1 for the axis parameter - PeriodIndex.tolist now boxes to Period (GH3178_) + - PeriodIndex.get_loc KeyError now reports Period instead of ordinal (GH3179_) .. _GH622: https://github.com/pydata/pandas/issues/622 .. _GH797: https://github.com/pydata/pandas/issues/797 @@ -303,6 +304,7 @@ pandas 0.11.0 .. _GH3094: https://github.com/pydata/pandas/issues/3094 .. _GH3130: https://github.com/pydata/pandas/issues/3130 .. _GH3178: https://github.com/pydata/pandas/issues/3178 +.. _GH3179: https://github.com/pydata/pandas/issues/3179 pandas 0.10.1 ============= diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py index 2804a1f00fb4b..39866768c0f25 100644 --- a/pandas/tseries/period.py +++ b/pandas/tseries/period.py @@ -887,8 +887,11 @@ def get_loc(self, key): except TypeError: pass - key = Period(key, self.freq).ordinal - return self._engine.get_loc(key) + key = Period(key, self.freq) + try: + return self._engine.get_loc(key.ordinal) + except KeyError as inst: + raise KeyError(repr(key)) def slice_locs(self, start=None, end=None): """ diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index 5f2fa1eb69d63..0737100d6315a 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -1926,6 +1926,14 @@ def test_to_datetime_1703(self): result = index.to_datetime() self.assertEquals(result[0], Timestamp('1/1/2012')) + def test_get_loc_msg(self): + idx = period_range('2000-1-1', freq='A', periods=10) + bad_period = Period('2012', 'A') + try: + idx.get_loc(bad_period) + except KeyError as inst: + self.assert_(inst.message == repr(bad_period)) + def test_append_concat(self): # #1815 d1 = date_range('12/31/1990', '12/31/1999', freq='A-DEC')