Skip to content

BUG: tslib.tz_convert_single converts DST incorrectly #7782

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
sinhrks opened this issue Jul 18, 2014 · 8 comments
Closed

BUG: tslib.tz_convert_single converts DST incorrectly #7782

sinhrks opened this issue Jul 18, 2014 · 8 comments
Labels
Bug Internals Related to non-user accessible pandas implementation Timezones Timezone data dtype
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jul 18, 2014

Apply tz_convert_single to the same time representation with different tz should be all True?

import pandas as pd
import numpy as np
import datetime
import pytz

for i in range(9):
    utc_dt = datetime.datetime(2014, 3, 9, i, 0, tzinfo=pytz.timezone('UTC'))
    tz_dt = datetime.datetime(2014, 3, 9, i, 0, tzinfo=pytz.timezone('US/Eastern'))

    utc_ts = pd.Timestamp(utc_dt)
    tz_ts = pd.Timestamp(tz_dt)

    print(utc_ts, tz_ts)

    print(utc_ts.value == pd.tslib.tz_convert_single(tz_ts.value, pytz.timezone('UTC'),
          pytz.timezone('US/Eastern')))

    print(tz_ts.value == pd.tslib.tz_convert_single(utc_ts.value, pytz.timezone('US/Eastern'),
          pytz.timezone('UTC')))

Current Result

(Timestamp('2014-03-09 00:00:00+0000', tz='UTC'), Timestamp('2014-03-09 00:00:00-0500', tz='US/Eastern'))
True
True
(Timestamp('2014-03-09 01:00:00+0000', tz='UTC'), Timestamp('2014-03-09 01:00:00-0500', tz='US/Eastern'))
True
True
(Timestamp('2014-03-09 02:00:00+0000', tz='UTC'), Timestamp('2014-03-09 02:00:00-0500', tz='US/Eastern'))
True
True
(Timestamp('2014-03-09 03:00:00+0000', tz='UTC'), Timestamp('2014-03-09 03:00:00-0500', tz='US/Eastern'))
False
True
(Timestamp('2014-03-09 04:00:00+0000', tz='UTC'), Timestamp('2014-03-09 04:00:00-0500', tz='US/Eastern'))
False
True
(Timestamp('2014-03-09 05:00:00+0000', tz='UTC'), Timestamp('2014-03-09 05:00:00-0500', tz='US/Eastern'))
False
True
(Timestamp('2014-03-09 06:00:00+0000', tz='UTC'), Timestamp('2014-03-09 06:00:00-0500', tz='US/Eastern'))
False
True
(Timestamp('2014-03-09 07:00:00+0000', tz='UTC'), Timestamp('2014-03-09 07:00:00-0500', tz='US/Eastern'))
False
True
(Timestamp('2014-03-09 08:00:00+0000', tz='UTC'), Timestamp('2014-03-09 08:00:00-0500', tz='US/Eastern'))
False
False
@rockg
Copy link
Contributor

rockg commented Jul 18, 2014

Something isn't working right in the example. The tz offset should be 0400 once dst is active and 3/9 2:00 doesn't exist. The tz_ts/tz_dt aren't right.

@jreback
Copy link
Contributor

jreback commented Jul 18, 2014

Yeah the creation is off, you have to localize with the zone localizer

In [10]: pytz.timezone('US/Eastern').localize(datetime.datetime(2014,3,9,2))
Out[10]: datetime.datetime(2014, 3, 9, 2, 0, tzinfo=<DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD>)

In [11]: pytz.timezone('US/Eastern').localize(datetime.datetime(2014,3,9,3))
Out[11]: datetime.datetime(2014, 3, 9, 3, 0, tzinfo=<DstTzInfo 'US/Eastern' EDT-1 day, 20:00:00 DST>)

@sinhrks
Copy link
Member Author

sinhrks commented Jul 18, 2014

Ah, modified example and result.

import pandas as pd
import numpy as np
import datetime
import pytz


for i in range(9):
    utc_ts = pd.Timestamp('2014-03-09 {0:02d}:00'.format(i), tz='UTC')
    tz_ts = pd.Timestamp('2014-03-09 {0:02}:00'.format(i), tz='US/Eastern')

    print(utc_ts, tz_ts)

    print(utc_ts.value == pd.tslib.tz_convert_single(tz_ts.value, pytz.timezone('UTC'),
          pytz.timezone('US/Eastern')))

    print(tz_ts.value == pd.tslib.tz_convert_single(utc_ts.value, pytz.timezone('US/Eastern'),
          pytz.timezone('UTC')))

Updated Result

(Timestamp('2014-03-09 00:00:00+0000', tz='UTC'), Timestamp('2014-03-09 00:00:00-0500', tz='US/Eastern'))
True
True
(Timestamp('2014-03-09 01:00:00+0000', tz='UTC'), Timestamp('2014-03-09 01:00:00-0500', tz='US/Eastern'))
True
True
(Timestamp('2014-03-09 02:00:00+0000', tz='UTC'), Timestamp('2014-03-09 02:00:00-0500', tz='US/Eastern'))
False
True
(Timestamp('2014-03-09 03:00:00+0000', tz='UTC'), Timestamp('2014-03-09 03:00:00-0400', tz='US/Eastern'))
True
False
(Timestamp('2014-03-09 04:00:00+0000', tz='UTC'), Timestamp('2014-03-09 04:00:00-0400', tz='US/Eastern'))
True
False
(Timestamp('2014-03-09 05:00:00+0000', tz='UTC'), Timestamp('2014-03-09 05:00:00-0400', tz='US/Eastern'))
True
False
(Timestamp('2014-03-09 06:00:00+0000', tz='UTC'), Timestamp('2014-03-09 06:00:00-0400', tz='US/Eastern'))
True
False
(Timestamp('2014-03-09 07:00:00+0000', tz='UTC'), Timestamp('2014-03-09 07:00:00-0400', tz='US/Eastern'))
True
False
(Timestamp('2014-03-09 08:00:00+0000', tz='UTC'), Timestamp('2014-03-09 08:00:00-0400', tz='US/Eastern'))
True
True

@sinhrks
Copy link
Member Author

sinhrks commented Jul 19, 2014

I understand UTC <-> local conversion results can differ on edges of DST because it has timestamps which is invalid. If test case added in #7798 test_tslib_tz_convert_dst looks correct, please close this.

@jreback
Copy link
Contributor

jreback commented Jul 19, 2014

@rockg can you have a look....

@jreback
Copy link
Contributor

jreback commented Jul 19, 2014

@sinhrks so this is indepent of #7798 ?

@sinhrks
Copy link
Member Author

sinhrks commented Jul 19, 2014

Yes, independent. (Background was considering test cases for #7798, though)

@jreback jreback added this to the 0.15.0 milestone Jul 21, 2014
@sinhrks
Copy link
Member Author

sinhrks commented Aug 3, 2014

@jreback pls close this, as curretn tresults are correct.

@jreback jreback closed this as completed Aug 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Internals Related to non-user accessible pandas implementation Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants