Skip to content

Commit

Permalink
BUG: PeriodIndex.get_loc KeyError now reports Period instead of ordinal
Browse files Browse the repository at this point in the history
  • Loading branch information
changhiskhan committed Mar 27, 2013
1 parent 91ad389 commit 30fba73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
=============
Expand Down
7 changes: 5 additions & 2 deletions pandas/tseries/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 8 additions & 0 deletions pandas/tseries/tests/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 30fba73

Please sign in to comment.