DataFrame.to_records() converts DatetimeIndex to datetime object, not np.datetime64 · Issue #18160 · pandas-dev/pandas (original) (raw)

This code:

df = pd.DataFrame([pd.to_datetime('2017-11-07')], [pd.to_datetime('2017-11-08')]) df.to_records()

Produces a totally different column type for the index vs the data:

rec.array([(datetime.datetime(2017, 11, 8, 0, 0), '2017-11-07T00:00:00.000000000')], 
          dtype=[('index', 'O'), ('0', '<M8[ns]')])

It should produce:

rec.array([('2017-11-08T00:00:00.000000000', '2017-11-07T00:00:00.000000000')], 
          dtype=[('index', '<M8[ns]'), ('0', '<M8[ns]')])

I'm using Pandas 0.20.3, NumPy 1.13.1, and Python 3.5.3.