Skip to content

Losing Nanosecond precision upon conversion to DatetimeIndex #2252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lterry-t opened this issue Nov 14, 2012 · 7 comments
Closed

Losing Nanosecond precision upon conversion to DatetimeIndex #2252

lterry-t opened this issue Nov 14, 2012 · 7 comments
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@lterry-t
Copy link

All,

I am experiencing a problem when converting from a TimeSeries to a DatetimeIndex. In the code below, I create a TimeSeries of nanosecond precision TimeStamps. I then convert it to a DatetimeIndex and lose the nanosecond precision (but maintain the microseconds). This appears to be a bug as the resulting elements of DatetimeIndex are of time TimeStamp and can handle nanosecond precision. Please see the snippet below.

Any help/resolution would be greatly appreciated.

Thanks,
Joe

In [233]: t1 = pandas.Timestamp((1352934390*1000000000)+1000000+1000+1)

In [234]: t2 = pandas.Timestamp((1352934390*1000000000)+1000000+1000+5)

In [235]: timeseries = pandas.TimeSeries([t1,t2])

In [236]: timeseries[0]
Out[236]: <Timestamp: 2012-11-14 23:06:30.001001001>

In [237]: datetimeindex = pandas.DatetimeIndex(timeseries)

In [238]: datetimeindex[0]
Out[238]: <Timestamp: 2012-11-14 23:06:30.001001>

In [236]: timeseries[0]
Out[236]: <Timestamp: 2012-11-14 23:06:30.001001001>
@kajdogg
Copy link

kajdogg commented Nov 15, 2012

Joe, I think your point is obscured by the markup behavior on < and >. I see the same puzzling behavior :

t1 = pandas.Timestamp((1352934390_1000000000)+1000000+1000+1)
t2 = pandas.Timestamp((1352934390_1000000000)+1000000+1000+5)
timeseries = pandas.TimeSeries([t1,t2])
timeseries[0]
<Timestamp: 2012-11-14 23:06:30.001001001>

datetimeindex = pandas.DatetimeIndex(timeseries)
datetimeindex[0]
<Timestamp: 2012-11-14 23:06:30.001001>
timeseries[0]
<Timestamp: 2012-11-14 23:06:30.001001001>

the last two timestamps are not the same

@wesm
Copy link
Member

wesm commented Nov 15, 2012

Looks like a bug. Will have to wait for 0.9.2 as I just cut 0.9.1 release-- will fix in the dev version as soon as we can

@lterry-t
Copy link
Author

Kajdogg, thanks for fixing. Wes, thanks for the quick response! I'll keep an eye out for it.

@angryoxen
Copy link

Not sure how big your series is, but getting the raw epoch nanoseconds out of the Timestamps works, if you have time for the extraction:

import pandas
t1 = pandas.Timestamp((1352934390_1000000000)+1000000+1000+1)
t2 = pandas.Timestamp((1352934390_1000000000)+1000000+1000+5)
timeseries = pandas.TimeSeries([t1,t2])
datetimeindex = pandas.DatetimeIndex([t.value for t in timeseries])
datetimeindex[0]

=> Timestamp: 2012-11-14 23:06:30.001001001

@changhiskhan
Copy link
Contributor

This should be fixed on master now. Do you want to give it a shot?

@lterry-t
Copy link
Author

Works great now. Thanks for the quick fix!!

@changhiskhan
Copy link
Contributor

sweet. thanks for the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

5 participants