ENH: Add full tz aware support for IntervalIndex · Issue #18537 · pandas-dev/pandas (original) (raw)

Problem description

The fixes in #18424 allow for and IntervalIndex to be constructed with tz aware timestamps, but there are a few attributes/methods that still do not work properly with tz aware:

Code Sample, a copy-pastable example if possible

Setup:

In [2]: start = pd.Timestamp('2017-01-01', tz='US/Eastern') ...: index = pd.interval_range(start, periods=3) ...: index ...: Out[2]: IntervalIndex([(2017-01-01, 2017-01-02], (2017-01-02, 2017-01-03], (2017-01-03, 2017-01-04]] closed='right', dtype='interval[datetime64[ns, US/Eastern]]')

IntervalIndex.mid returns tz naive:

In [3]: index.mid Out[3]: DatetimeIndex(['2017-01-01 17:00:00', '2017-01-02 17:00:00', '2017-01-03 17:00:00'], dtype='datetime64[ns]', freq=None)

get_indexer raises when passed an IntervalIndex:

In [4]: index.get_indexer(index[:-1])

TypeError: cannot determine next label for type <class 'pandas.core.indexes.datetimes.DatetimeIndex'>

Differing tz:

In [5]: left = pd.date_range('2017-01-01', periods=3, tz='US/Eastern') ...: right = pd.date_range('2017-01-02', periods=3, tz='US/Pacific') ...: index = pd.IntervalIndex.from_arrays(left, right) ...: index ...: Out[5]: IntervalIndex([(2017-01-01, 2017-01-02], (2017-01-02, 2017-01-03], (2017-01-03, 2017-01-04]] closed='right', dtype='interval[datetime64[ns, US/Eastern]]')

In [6]: index.left.dtype Out[6]: datetime64[ns, US/Eastern]

In [7]: index.right.dtype Out[7]: datetime64[ns, US/Pacific]