Permalink
Browse files

BUG: fixed DataFrame.to_records() error with datetime64, #1908

  • Loading branch information...
1 parent 09bde7d commit e17c07f52f55e7b00ec387c31e229e678fd4ae7d @svaksha committed Dec 16, 2012
Showing with 10 additions and 2 deletions.
  1. +5 −2 pandas/core/frame.py
  2. +5 −0 pandas/tests/test_frame.py
@@ -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):
@@ -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'))

0 comments on commit e17c07f

Please sign in to comment.