Skip to content

apply() silently removes time zone information from DateTime values #12382

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
adamdivak opened this issue Feb 18, 2016 · 2 comments
Closed

apply() silently removes time zone information from DateTime values #12382

adamdivak opened this issue Feb 18, 2016 · 2 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Timezones Timezone data dtype

Comments

@adamdivak
Copy link

Hi,

apply() silently removes time zone information from DateTime values. I think this bug is related to #10668, but it is apparently not the same.

Code Sample, a copy-pastable example if possible

import pandas as pd
date_range = pd.date_range('1/1/2011', periods=5, freq='H')
date_range = date_range.tz_localize('Europe/Budapest')
s = pd.Series(date_range, index=date_range)
s
2011-01-01 00:00:00+01:00   2011-01-01 00:00:00+01:00
2011-01-01 01:00:00+01:00   2011-01-01 01:00:00+01:00
2011-01-01 02:00:00+01:00   2011-01-01 02:00:00+01:00
2011-01-01 03:00:00+01:00   2011-01-01 03:00:00+01:00
2011-01-01 04:00:00+01:00   2011-01-01 04:00:00+01:00
Freq: H, dtype: datetime64[ns, Europe/Budapest]

Create a simple apply function which does nothing but returns each value. Notice that that values are converted to UTC by default and the timezone information is lost, and a timezone-naive value is returned instead.

def apply_function(dt):
    return dt
s.apply(apply_function)
2011-01-01 00:00:00+01:00   2010-12-31 23:00:00
2011-01-01 01:00:00+01:00   2011-01-01 00:00:00
2011-01-01 02:00:00+01:00   2011-01-01 01:00:00
2011-01-01 03:00:00+01:00   2011-01-01 02:00:00
2011-01-01 04:00:00+01:00   2011-01-01 03:00:00
Freq: H, dtype: datetime64[ns]

Expected Output

Apply is expected to return the original series, values unchanged, including the time zone information.

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.4.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.2.0-27-generic
machine: x86_64
processor: 
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.17.1
nose: None
pip: 8.0.2
setuptools: 20.1.1
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.17.0
statsmodels: 0.6.1
IPython: 4.1.1
sphinx: None
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: 0.9.4
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: None
@rockg
Copy link
Contributor

rockg commented Feb 18, 2016

I believe this is the same as #11757 which I have neglected to finish. It was turning out to be trickier than I had hoped.

@jreback jreback added Bug Duplicate Report Duplicate issue or pull request Timezones Timezone data dtype labels Feb 18, 2016
@jreback
Copy link
Contributor

jreback commented Feb 18, 2016

I agree. @yosuah thanks for the report.

@jreback jreback closed this as completed Feb 18, 2016
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 Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants