Skip to content

Commit

Permalink
BUG: Series.tolist override for datetime64 #2447
Browse files Browse the repository at this point in the history
  • Loading branch information
changhiskhan committed Dec 7, 2012
1 parent 0a3fd63 commit c3e75db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,15 @@ def copy(self, order='C'):
return Series(self.values.copy(order), index=self.index,
name=self.name)

def tolist(self):
"""
Convert Series to a nested list
Overrides numpy.ndarray.tolist
"""
if com.is_datetime64_dtype(self):
return self.astype(object).values.tolist()
return self.values.tolist()

def to_dict(self):
"""
Convert Series to {label -> value} dict
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,18 @@ def test_to_csv_unicode_index(self):

assert_series_equal(s, s2)

def test_tolist(self):
rs = self.ts.tolist()
xp = self.ts.values.tolist()
assert_almost_equal(rs, xp)

#datetime64
s = Series(self.ts.index)
rs = s.tolist()
xp = s.astype(object).values.tolist()
assert_almost_equal(rs, xp)
self.assertEqual(self.ts.index[0], rs[0])

def test_to_dict(self):
self.assert_(np.array_equal(Series(self.ts.to_dict()), self.ts))

Expand Down

0 comments on commit c3e75db

Please sign in to comment.