Skip to content

Commit 91ad389

Browse files
committed
BUG: PeriodIndex.tolist boxes to list of Periods #3178
1 parent 3844347 commit 91ad389

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pandas 0.11.0
228228
- Fixed bug in groupby apply when kernel generate list of arrays having unequal len (GH1738_)
229229
- fixed handling of rolling_corr with center=True which could produce corr>1 (GH3155_)
230230
- Fixed issues where indices can be passed as 'index/column' in addition to 0/1 for the axis parameter
231+
- PeriodIndex.tolist now boxes to Period (GH3178_)
231232

232233
.. _GH622: https://github.com/pydata/pandas/issues/622
233234
.. _GH797: https://github.com/pydata/pandas/issues/797
@@ -301,6 +302,7 @@ pandas 0.11.0
301302
.. _GH3075: https://github.com/pydata/pandas/issues/3075
302303
.. _GH3094: https://github.com/pydata/pandas/issues/3094
303304
.. _GH3130: https://github.com/pydata/pandas/issues/3130
305+
.. _GH3178: https://github.com/pydata/pandas/issues/3178
304306

305307
pandas 0.10.1
306308
=============

pandas/tseries/period.py

+6
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,12 @@ def _mpl_repr(self):
768768
# how to represent ourselves to matplotlib
769769
return self._get_object_array()
770770

771+
def tolist(self):
772+
"""
773+
Return a list of Period objects
774+
"""
775+
return self._get_object_array().tolist()
776+
771777
def to_timestamp(self, freq=None, how='start'):
772778
"""
773779
Cast to DatetimeIndex

pandas/tseries/tests/test_period.py

+8
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,14 @@ def test_periods_number_check(self):
12261226
self.assertRaises(
12271227
ValueError, period_range, '2011-1-1', '2012-1-1', 'B')
12281228

1229+
def test_tolist(self):
1230+
index = PeriodIndex(freq='A', start='1/1/2001', end='12/1/2009')
1231+
rs = index.tolist()
1232+
[self.assert_(isinstance(x, Period)) for x in rs]
1233+
1234+
recon = PeriodIndex(rs)
1235+
self.assert_(index.equals(recon))
1236+
12291237
def test_to_timestamp(self):
12301238
index = PeriodIndex(freq='A', start='1/1/2001', end='12/1/2009')
12311239
series = Series(1, index=index, name='foo')

0 commit comments

Comments
 (0)