TST: add datetimelike tests for tz-aware DatetimeIndex by azjps · Pull Request #17694 · pandas-dev/pandas (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_holder
here will also be DatetimeIndex
, which isn't sufficient because DatetimeIndex
constructor doesn't have TZ information. The problem is that the constructor DatetimeIndex(index.values, ...)
is getting a numpy datetime64 array of tz-naive timestamps. There currently doesn't seem to be an argument to DatetimeIndex
's constructor to tell it what timezone to convert to presuming that the input data is UTC (the tz=
argument localizes to the specified timezone), so there's not currently a way to do this through init_kwargs
. Hence why I currently call _fix_tz
to first localize to UTC and then convert to the TZ of create_index()
.
To sum up:
index = create_index()
hasTZ = US/Eastern
result = index_type(index.values)
hasTZ = None
❌result = index_type(index.values, tz=index.tz)
hasTZ = US/Eastern
, but because of re-localization has been shifted again, and thus has differently underlying values. ❌self._fix_tz(result, index)
does haveTZ = US/Eastern
I can do the suggested refactor though.