Skip to content

to_datetime does not handle timezones correctly for timestamps #9341

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
CodeSturgeon opened this issue Jan 22, 2015 · 1 comment
Closed

to_datetime does not handle timezones correctly for timestamps #9341

CodeSturgeon opened this issue Jan 22, 2015 · 1 comment
Labels
Bug Timezones Timezone data dtype

Comments

@CodeSturgeon
Copy link

It seems that the to_datetime function always assumes that a timestamp is in local time and converts it to UTC. This does not seem to be the case with converting from strings.

This code:

from datetime import datetime
import time
import pandas as pd
now = datetime.now()
ts = time.mktime(now.timetuple())
print ts
print now.strftime('%Y-%m-%d %H:%M')
print pd.to_datetime(ts, unit='s')
print pd.to_datetime(ts, unit='s', utc=True)
print pd.to_datetime(now.strftime('%Y-%m-%d %H:%M'))

Give this result (pandas 0.15.1):

1421967906.0
2015-01-22 18:05
2015-01-22 23:05:06
2015-01-22 23:05:06+00:00
2015-01-22 18:05:00

Note that when to_datetime is converting a timestamp five hours are added no matter the utc= arg value.

@jreback
Copy link
Contributor

jreback commented Jan 22, 2015

thanks for reporting
this is a dupe of #6415 pull requests are welcome

@jreback jreback closed this as completed Jan 22, 2015
@jreback jreback added Community Bug Timezones Timezone data dtype and removed Community labels Jan 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants