Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit e17c07f52f55e7b00ec387c31e229e678fd4ae7d 1 parent 09bde7d
SVAKSHA authored

Showing 2 changed files with 10 additions and 2 deletions. Show diff stats Hide diff stats

  1. +5 2 pandas/core/frame.py
  2. +5 0 pandas/tests/test_frame.py
7 pandas/core/frame.py
@@ -1066,8 +1066,11 @@ def to_records(self, index=True):
1066 1066 y : recarray
1067 1067 """
1068 1068 if index:
1069   - arrays = [self.index.values] + [self[c].values
1070   - for c in self.columns]
  1069 + if (com.is_datetime64_dtype(self.index)):
  1070 + arrays = [self.index.asobject.values] + [self[c].values for c in self.columns]
  1071 + else:
  1072 + arrays = [self.index.values] + [self[c].values for c in self.columns]
  1073 +
1071 1074 count = 0
1072 1075 index_names = self.index.names
1073 1076 if isinstance(self.index, MultiIndex):
5 pandas/tests/test_frame.py
@@ -2668,6 +2668,11 @@ def test_to_json_except(self):
2668 2668 df = DataFrame([1, 2, 3])
2669 2669 self.assertRaises(ValueError, df.to_json, orient="garbage")
2670 2670
  2671 + def test_array_index_asobject(self):
  2672 + df = DataFrame([["one", "two", "three"], ["four", "five", "six"]], index=pan.date_range("2012-01-01", "2012-01-02"))
  2673 + self.assert_(df.to_records()['index'][0] == df.index[0])
  2674 +
  2675 +
2671 2676 def test_from_records_to_records(self):
2672 2677 # from numpy documentation
2673 2678 arr = np.zeros((2,),dtype=('i4,f4,a10'))

0 comments on commit e17c07f

Please sign in to comment.
Something went wrong with that request. Please try again.