Closed
Description
Timestamp
constructor raises an exception when given iso8601 string with UTC offset and a desired timezone. When given datetime
object with timezone and a desired timezone, it gives a correct string but incorrect internal timestamp value.
In [1]: from pandas import Timestamp as ts, DataFrame as df
In [2]: from datetime import datetime as dt
In [3]: from pytz import timezone as tz
In [4]: UTC='UTC'
In [5]: EST='US/Eastern'
In [6]: CST='US/Central'
In [7]: # all the following should have the same timestamp value
In [8]: # (commented lines throw exceptions!!)
In [9]: tss=[ts("2012-01-02 01:00:00+00:00"),
...: # ts("2012-01-02 01:00:00+00:00", tz=EST),
...: ts("2012-01-01 20:00:00", tz=EST),
...: ts(dt(2012,1,1,20,0,0,tzinfo=tz(EST))),
...: ts(dt(2012,1,1,19,0,0,tzinfo=tz(CST))),
...: ts(dt(2012,1,1,20,0,0,tzinfo=tz(EST)), tz=EST),
...: ts(dt(2012,1,1,19,0,0,tzinfo=tz(CST)), tz=EST),
...: ts("2012-01-01 20:00:00-05:00"),
...: ts("2012-01-01 19:00:00-06:00"),
...: # ts("2012-01-01 20:00:00-05:00", tz=EST),
...: # ts("2012-01-01 19:00:00-06:00", tz=EST),
...: ts(1325466000000000000, tz=UTC),
...: ts(1325466000000000000, tz=EST)]
In [10]: strs = [str(ts) for ts in tss]
In [11]: vals = [(ts.value/1000000000000) for ts in tss]
In [12]: df({'strs' : strs, 'vals' : vals})
Out[12]:
strs vals
0 2012-01-02 01:00:00+00:00 1325466
1 2012-01-01 20:00:00-05:00 1325466
2 2012-01-01 20:00:00-05:00 1325466
3 2012-01-01 19:00:00-06:00 1325466
4 2012-01-01 20:00:00-05:00 1325448 <-- bad value!!
5 2012-01-01 20:00:00-05:00 1325448 <-- bad value!!
6 2012-01-01 20:00:00-05:00 1325466
7 2012-01-01 19:00:00-06:00 1325466
8 2012-01-02 01:00:00+00:00 1325466
9 2012-01-01 20:00:00-05:00 1325466