Skip to content

DataFrame.to_records converts dates wrongly #1908

Closed
@ukch

Description

@ukch

Possibly related to #1720:

When converting a DataFrame to a recarray using df.to_records, date indexes are incorrectly converted.

>>> import pandas
>>> df = pandas.DataFrame([["one", "two", "three"], ["four", "five", "six"]], index=pandas.date_range("2012-01-01", "2012-01-02"))
>>> df
               0     1      2
2012-01-01   one   two  three
2012-01-02  four  five    six
>>> df.to_records()
rec.array([(datetime.datetime(1970, 1, 16, 224, 0), 'one', 'two', 'three'),
       (datetime.datetime(1970, 1, 16, 248, 0), 'four', 'five', 'six')], 
      dtype=[('index', ('<M8[ns]', {})), ('0', '|O8'), ('1', '|O8'), ('2', '|O8')])

Notice the dates have been converted to 1970, even though the original dates were in 2012.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions