Skip to content
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

wrong addition between Series of type datetime64 and timedelta when tz is set and different from UTC #14022

Closed
sdementen opened this issue Aug 17, 2016 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Numeric Operations Arithmetic, Comparison, and Logical operations Timezones Timezone data dtype

Comments

@sdementen
Copy link
Contributor

It seems there is an issue when adding a timedelta to a Series of type datetime64[ns, some tz]. There seems to be an issue with the offset/DST.

Code Sample, a copy-pastable example if possible

import pandas

sr = pandas.Series(pandas.DatetimeIndex(["2016-11-03 16:00:00+01:00", "2016-10-25 17:00:00+02:00"]).tz_localize("UTC").tz_convert(tz="Europe/Brussels"))
print(sr)
print(sr + pandas.to_timedelta(0, unit='h'))

Actual Output

0   2016-11-03 16:00:00+01:00
1   2016-10-25 17:00:00+02:00
dtype: datetime64[ns, Europe/Brussels]
0   2016-11-03 16:00:00+01:00
1   2016-10-25 16:00:00+02:00
dtype: datetime64[ns, Europe/Brussels]

Expected Output

0   2016-11-03 16:00:00+01:00
1   2016-10-25 17:00:00+02:00
dtype: datetime64[ns, Europe/Brussels]
0   2016-11-03 16:00:00+01:00
1   2016-10-25 17:00:00+02:00
dtype: datetime64[ns, Europe/Brussels]

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 23.0.0
Cython: None
numpy: 1.11.0
scipy: 0.17.1
statsmodels: None
xarray: None
IPython: 4.2.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.1
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: None
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: None
html5lib: None
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext)
jinja2: 2.8
boto: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Aug 17, 2016

dupe of #13905

@jreback jreback closed this as completed Aug 17, 2016
@jreback jreback added Duplicate Report Duplicate issue or pull request Numeric Operations Arithmetic, Comparison, and Logical operations Timezones Timezone data dtype labels Aug 17, 2016
@jreback jreback added this to the No action milestone Aug 17, 2016
@sdementen
Copy link
Contributor Author

I have the impression it is not exactly the same bug. It appears specifically when

import pandas
sr =  pandas.Series(pandas.DatetimeIndex(['2016-06-28 05:30', '2016-06-28 05:31'], type='datetime64[ns, America/Chicago]'))
print(sr)
print((sr + pandas.to_timedelta(0, unit='h')))

gives

0   2016-06-28 05:30:00-05:00
1   2016-06-28 05:31:00-05:00
dtype: datetime64[ns, America/Chicago]
0   2016-06-28 05:30:00-05:00
1   2016-06-28 05:31:00-05:00
dtype: datetime64[ns, America/Chicago]

  • adding the timedelta to a Series (and not an index). If we use a DateTimeIndex instead of a Series
sr =  pandas.DatetimeIndex(["2016-12-03 16:00:00", "2016-10-25 17:00:00"], dtype='datetime64[ns, Europe/Brussels]')
print(sr)
print((sr + pandas.to_timedelta(0, unit='h')))

it works as expected

DatetimeIndex(['2016-12-03 16:00:00+01:00', '2016-10-25 17:00:00+02:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)
DatetimeIndex(['2016-12-03 16:00:00+01:00', '2016-10-25 17:00:00+02:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Numeric Operations Arithmetic, Comparison, and Logical operations Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants