Closed
Description
Code Sample, a copy-pastable example if possible
With pandas 0.25.3 or master,
In [2]: arr = pd.arrays.IntervalArray.from_breaks(pd.date_range('2000', periods=4))
In [3]: arr.shift()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-e840978d5de6> in <module>
----> 1 arr.shift()
~/miniconda3/envs/pandas=0.25.1/lib/python3.7/site-packages/pandas/core/arrays/base.py in shift(self, periods, fill_value)
567
568 empty = self._from_sequence(
--> 569 [fill_value] * min(abs(periods), len(self)), dtype=self.dtype
570 )
571 if periods > 0:
~/miniconda3/envs/pandas=0.25.1/lib/python3.7/site-packages/pandas/core/arrays/interval.py in _from_sequence(cls, scalars, dtype, copy)
236 @classmethod
237 def _from_sequence(cls, scalars, dtype=None, copy=False):
--> 238 return cls(scalars, dtype=dtype, copy=copy)
239
240 @classmethod
~/miniconda3/envs/pandas=0.25.1/lib/python3.7/site-packages/pandas/core/arrays/interval.py in __new__(cls, data, closed, dtype, copy, verify_integrity)
176 copy=copy,
177 dtype=dtype,
--> 178 verify_integrity=verify_integrity,
179 )
180
~/miniconda3/envs/pandas=0.25.1/lib/python3.7/site-packages/pandas/core/arrays/interval.py in _simple_new(cls, left, right, closed, copy, dtype, verify_integrity)
196 raise TypeError(msg.format(dtype=dtype))
197 elif dtype.subtype is not None:
--> 198 left = left.astype(dtype.subtype)
199 right = right.astype(dtype.subtype)
200
~/miniconda3/envs/pandas=0.25.1/lib/python3.7/site-packages/pandas/core/indexes/numeric.py in astype(self, dtype, copy)
367 "values are required for conversion"
368 ).format(dtype=dtype)
--> 369 raise TypeError(msg)
370 elif (
371 is_integer_dtype(dtype) and not is_extension_array_dtype(dtype)
TypeError: Cannot convert Float64Index to dtype datetime64[ns]; integer values are required for conversion
Problem description
We should be able to preserve the interval dtype, by placing NaT.
Expected Output
IntervalArray([NaT, (2000-01-01, 2000-01-02], (2000-01-02, 2000-01-03]],
closed='right',
dtype='interval[datetime64[ns]]')