Recognize timezoned labels when accessing dataframes. by 1kastner · Pull Request #17920 · pandas-dev/pandas (original) (raw)

so you need to do something different here. leave the dates that are generated in the current tz (e.g. self.tz). Then you need to convert it to the parsed_tz, BUT then you need to localize back into the original timezone. There are a number of cases, here's an example.

# index in US/Eastern, parsed in UTC
In [22]: pd.Timestamp('20130101',tz='US/Eastern')
Out[22]: Timestamp('2013-01-01 00:00:00-0500', tz='US/Eastern')
00:00+0000', tz='UTC')

In [24]: pd.Timestamp('20130101',tz='US/Eastern').tz_convert('UTC').tz_localize(None).tz_localize('US/Eastern')
Out[24]: Timestamp('2013-01-01 05:00:00-0500', tz='US/Eastern')

# index is naive, parsed is UTC, ineffect no change here
In [25]: pd.Timestamp('20130101')
Out[25]: Timestamp('2013-01-01 00:00:00')

In [26]: pd.Timestamp('20130101').tz_localize('UTC').tz_localize(None)
Out[26]: Timestamp('2013-01-01 00:00:00')

As I am writing this, it looks overly complicated. I might choose instead to raise if the timezones don't match (they can be same tz or both None).