Skip to content

BUG: to_datetime with utc=True for Series #15760

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
albertvillanova opened this issue Mar 21, 2017 · 1 comment
Closed

BUG: to_datetime with utc=True for Series #15760

albertvillanova opened this issue Mar 21, 2017 · 1 comment
Labels
Bug Duplicate Report Duplicate issue or pull request

Comments

@albertvillanova
Copy link
Contributor

albertvillanova commented Mar 21, 2017

Code Sample, a copy-pastable example if possible

In [2]: ts = 1.4884427244831782e+18

In [3]: pd.to_datetime(ts, utc=True)
Out[3]: Timestamp('2017-03-02 08:18:44.483178240+0000', tz='UTC')

In [4]: pd.to_datetime([ts], utc=True)
Out[4]: DatetimeIndex(['2017-03-02 08:18:44.483178240+00:00'], dtype='datetime64[ns, UTC]', freq=None)

In [5]: pd.to_datetime(pd.Series([ts]), utc=True)
Out[5]: 
0   2017-03-02 08:18:44.483178240
dtype: datetime64[ns]

Problem description

The argument utc=True in function to_datetime is not working when passing a Series, differently from other case, e.g. when passing a list or a scalar Unix timestamp.

Expected Output

The expected output is the same as the one given by

In [6]: pd.to_datetime(pd.Series([ts])).dt.tz_localize('UTC')
Out[6]: 
0   2017-03-02 08:18:44.483178240+00:00
dtype: datetime64[ns, UTC]

Another example: tz_convert

It is straightforward to convert to another time zone from a Unix timestamp or list:

In [7]: pd.to_datetime(ts, utc=True).tz_convert('Europe/Paris')
Out[7]: Timestamp('2017-03-02 09:18:44.483178240+0100', tz='Europe/Paris')

In [8]: pd.to_datetime([ts], utc=True).tz_convert('Europe/Paris')
Out[8]: DatetimeIndex(['2017-03-02 09:18:44.483178240+01:00'], dtype='datetime64[ns, Europe/Paris]', freq=None)

whereas for a Series:

In [9]: pd.to_datetime(pd.Series([ts])).dt.tz_localize('UTC').dt.tz_convert('Europe/Paris')
Out[9]: 
0   2017-03-02 09:18:44.483178240+01:00
dtype: datetime64[ns, Europe/Paris]

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 3.13.0-113-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: ca_ES.UTF-8 LOCALE: ca_ES.UTF-8

pandas: 0.19.2
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0.post20161106
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: 0.2.1

@jorisvandenbossche
Copy link
Member

@albertvillanova Thanks for the report! This is a duplicate of #6415
PRs welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants