Skip to content

Commit 9e5fc50

Browse files
committed
fixup! REF: IntervalIndex[IntervalArray]
1 parent 9b8564f commit 9e5fc50

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

pandas/core/indexes/interval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ def copy(self, deep=False, name=None):
412412

413413
@Appender(_index_shared_docs['astype'])
414414
def astype(self, dtype, copy=True):
415-
new_values = self.values.astype(dtype, copy=copy)
415+
with rewrite_exception('IntervalArray', self.__class__.__name__):
416+
new_values = self.values.astype(dtype, copy=copy)
416417
if is_interval_dtype(new_values):
417418
return self._shallow_copy(new_values.left, new_values.right)
418419
return super(IntervalIndex, self).astype(dtype, copy=copy)

pandas/tests/indexes/interval/test_astype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_astype_category(self, index):
5151
'timedelta64', 'timedelta64[ns]', 'datetime64', 'datetime64[ns]',
5252
'datetime64[ns, US/Eastern]'])
5353
def test_astype_cannot_cast(self, index, dtype):
54-
msg = 'Cannot cast IntervalArray to dtype'
54+
msg = 'Cannot cast IntervalIndex to dtype'
5555
with tm.assert_raises_regex(TypeError, msg):
5656
index.astype(dtype)
5757

pandas/tests/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,8 @@ def test_iter_box(self):
11941194
'datetime64[ns, US/Central]'),
11951195
(pd.TimedeltaIndex([10**10]), np.ndarray, 'm8[ns]'),
11961196
(pd.PeriodIndex([2018, 2019], freq='A'), np.ndarray, 'object'),
1197-
(pd.IntervalIndex.from_breaks([0, 1, 2]), pd.core.arrays.IntervalArray, 'interval'),
1197+
(pd.IntervalIndex.from_breaks([0, 1, 2]), pd.core.arrays.IntervalArray,
1198+
'interval'),
11981199
])
11991200
def test_values_consistent(array, expected_type, dtype):
12001201
l_values = pd.Series(array)._values

0 commit comments

Comments
 (0)