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

DatetimeIndex + TimeDelta gives wrong results when timezone is set #13905

Closed
jzwinck opened this issue Aug 4, 2016 · 1 comment · Fixed by #18884
Closed

DatetimeIndex + TimeDelta gives wrong results when timezone is set #13905

jzwinck opened this issue Aug 4, 2016 · 1 comment · Fixed by #18884
Labels
Bug good first issue Timedelta Timedelta data type Timezones Timezone data dtype
Milestone

Comments

@jzwinck
Copy link
Contributor

jzwinck commented Aug 4, 2016

When I add a time delta to a DatetimeIndex which is tz-aware, the results appear as UTC, but sometimes claim to be in the original non-UTC timezone.

Code

import pandas as pd
index = pd.DatetimeIndex(['2016-06-28 05:30', '2016-06-28 05:31'], dtype='datetime64[ns, America/Chicago]')
offset = pd.Series(['00:00:05', '00:00:05'], dtype='timedelta64[ns]', index=index)
print(index + offset)
print(index + offset.values)

Actual Output

2016-06-28 05:30:00-05:00   2016-06-28 10:30:05
2016-06-28 05:31:00-05:00   2016-06-28 10:31:05
dtype: datetime64[ns]
DatetimeIndex(['2016-06-28 10:30:05-05:00', '2016-06-28 10:31:05-05:00'], dtype='datetime64[ns, America/Chicago]', freq=None)

Expected Output

2016-06-28 05:30:00-05:00   2016-06-28 05:30:05-05:00
2016-06-28 05:31:00-05:00   2016-06-28 05:31:05-05:00
dtype: datetime64[ns]
DatetimeIndex(['2016-06-28 05:30:05-05:00', '2016-06-28 05:31:05-05:00'], dtype='datetime64[ns, America/Chicago]', freq=None)

Note however that this does print the expected result:

print(index + pd.to_timedelta('00:00:05'))

I'm using Pandas 0.18.1.

@jreback
Copy link
Contributor

jreback commented Aug 4, 2016

yep, thought we had an issue about this, but can't seem to find it.

@jreback jreback added Bug Difficulty Novice Timedelta Timedelta data type Timezones Timezone data dtype labels Aug 4, 2016
@jreback jreback added this to the Next Major Release milestone Aug 4, 2016
jbrockmendel added a commit to jbrockmendel/pandas that referenced this issue Dec 20, 2017
ser + index lossed timezone
closes pandas-dev#13905

index + ser retained timezone but returned a DatetimeIndex
@jreback jreback modified the milestones: Next Major Release, 0.23.0 Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug good first issue Timedelta Timedelta data type Timezones Timezone data dtype
Projects
None yet
3 participants