diff --git a/pandas/tests/indexes/interval/test_astype.py b/pandas/tests/indexes/interval/test_astype.py index 34ce810e32273..840e3f641e8ba 100644 --- a/pandas/tests/indexes/interval/test_astype.py +++ b/pandas/tests/indexes/interval/test_astype.py @@ -1,3 +1,5 @@ +import re + import numpy as np import pytest @@ -153,22 +155,25 @@ def test_subtype_integer(self, subtype): with pytest.raises(ValueError, match=msg): index.insert(0, np.nan).astype(dtype) - @pytest.mark.xfail(reason="GH#15832") + @pytest.mark.parametrize("subtype", ["int64", "uint64"]) + def test_subtype_integer_with_non_integer_borders(self, subtype): + index = interval_range(0.0, 3.0, freq=0.25) + dtype = IntervalDtype(subtype) + result = index.astype(dtype) + expected = IntervalIndex.from_arrays( + index.left.astype(subtype), index.right.astype(subtype), closed=index.closed + ) + tm.assert_index_equal(result, expected) + def test_subtype_integer_errors(self): # float64 -> uint64 fails with negative values index = interval_range(-10.0, 10.0) dtype = IntervalDtype("uint64") - with pytest.raises(ValueError): - index.astype(dtype) - - # float64 -> integer-like fails with non-integer valued floats - index = interval_range(0.0, 10.0, freq=0.25) - dtype = IntervalDtype("int64") - with pytest.raises(ValueError): - index.astype(dtype) - - dtype = IntervalDtype("uint64") - with pytest.raises(ValueError): + msg = re.escape( + "Cannot convert interval[float64] to interval[uint64]; subtypes are " + "incompatible" + ) + with pytest.raises(TypeError, match=msg): index.astype(dtype) @pytest.mark.parametrize("subtype", ["datetime64[ns]", "timedelta64[ns]"])