Skip to content

Incorrect result when using to_datetime() on PeriodIndex #1703

@kdebrab

Description

@kdebrab

Pandas 0.8.1:

import pandas as pd
index = pd.period_range('1/1/2012',periods=4,freq='D')
index.to_datetime()

returns incorrectly:

<class 'pandas.tseries.index.DatetimeIndex'>
[1970-01-01 00:00:00.000015340, ..., 1970-01-01 00:00:00.000015343]
Length: 4, Freq: None, Timezone: None

The correct result is obtained though with to_timestamp() instead of to_datetime():

index.to_timestamp()

returns correctly:

<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01 00:00:00, ..., 2012-01-04 00:00:00]
Length: 4, Freq: D, Timezone: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions