Skip to content

Commit

Permalink
BUG: fixed DataFrame.to_records() error with datetime64, #1908
Browse files Browse the repository at this point in the history
  • Loading branch information
svaksha authored and changhiskhan committed Dec 18, 2012
1 parent 1751bae commit f971840
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,8 +1066,11 @@ def to_records(self, index=True):
y : recarray
"""
if index:
arrays = [self.index.values] + [self[c].values
for c in self.columns]
if (com.is_datetime64_dtype(self.index)):
arrays = [self.index.asobject.values] + [self[c].values for c in self.columns]
else:
arrays = [self.index.values] + [self[c].values for c in self.columns]

count = 0
index_names = self.index.names
if isinstance(self.index, MultiIndex):
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2668,6 +2668,11 @@ def test_to_json_except(self):
df = DataFrame([1, 2, 3])
self.assertRaises(ValueError, df.to_json, orient="garbage")

def test_array_index_asobject(self):
df = DataFrame([["one", "two", "three"], ["four", "five", "six"]], index=pan.date_range("2012-01-01", "2012-01-02"))
self.assert_(df.to_records()['index'][0] == df.index[0])


def test_from_records_to_records(self):
# from numpy documentation
arr = np.zeros((2,),dtype=('i4,f4,a10'))
Expand Down

0 comments on commit f971840

Please sign in to comment.