Skip to content

Commit 2cee459

Browse files
committed
BUG: override DatetimeIndex.tolist so it returns a list of Timestamp objects, close #1437
1 parent 553ac92 commit 2cee459

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/tseries/index.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ def asobject(self):
593593
raise ValueError(msg)
594594
return self._get_object_index()
595595

596+
def tolist(self):
597+
"""
598+
See ndarray.tolist
599+
"""
600+
return list(self.asobject)
601+
596602
def _get_object_index(self):
597603
boxed_values = _dt_box_array(self.asi8, self.offset, self.tz)
598604
return Index(boxed_values, dtype=object)

pandas/tseries/tests/test_timeseries.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,12 @@ def test_index_conversion(self):
10301030

10311031
self.assertRaises(ValueError, DatetimeIndex, ['a', 'b', 'c', 'd'])
10321032

1033+
def test_tolist(self):
1034+
rng = date_range('1/1/2000', periods=10)
1035+
1036+
result = rng.tolist()
1037+
self.assert_(isinstance(result[0], Timestamp))
1038+
10331039
def test_object_convert_fail(self):
10341040
idx = DatetimeIndex([NaT])
10351041
self.assertRaises(ValueError, idx.astype, 'O')

0 commit comments

Comments
 (0)