|
| 1 | +import re |
| 2 | + |
1 | 3 | import numpy as np
|
2 | 4 | import pytest
|
3 | 5 |
|
@@ -153,22 +155,25 @@ def test_subtype_integer(self, subtype):
|
153 | 155 | with pytest.raises(ValueError, match=msg):
|
154 | 156 | index.insert(0, np.nan).astype(dtype)
|
155 | 157 |
|
156 |
| - @pytest.mark.xfail(reason="GH#15832") |
| 158 | + @pytest.mark.parametrize("subtype", ["int64", "uint64"]) |
| 159 | + def test_subtype_integer_with_non_integer_borders(self, subtype): |
| 160 | + index = interval_range(0.0, 3.0, freq=0.25) |
| 161 | + dtype = IntervalDtype(subtype) |
| 162 | + result = index.astype(dtype) |
| 163 | + expected = IntervalIndex.from_arrays( |
| 164 | + index.left.astype(subtype), index.right.astype(subtype), closed=index.closed |
| 165 | + ) |
| 166 | + tm.assert_index_equal(result, expected) |
| 167 | + |
157 | 168 | def test_subtype_integer_errors(self):
|
158 | 169 | # float64 -> uint64 fails with negative values
|
159 | 170 | index = interval_range(-10.0, 10.0)
|
160 | 171 | dtype = IntervalDtype("uint64")
|
161 |
| - with pytest.raises(ValueError): |
162 |
| - index.astype(dtype) |
163 |
| - |
164 |
| - # float64 -> integer-like fails with non-integer valued floats |
165 |
| - index = interval_range(0.0, 10.0, freq=0.25) |
166 |
| - dtype = IntervalDtype("int64") |
167 |
| - with pytest.raises(ValueError): |
168 |
| - index.astype(dtype) |
169 |
| - |
170 |
| - dtype = IntervalDtype("uint64") |
171 |
| - with pytest.raises(ValueError): |
| 172 | + msg = re.escape( |
| 173 | + "Cannot convert interval[float64] to interval[uint64]; subtypes are " |
| 174 | + "incompatible" |
| 175 | + ) |
| 176 | + with pytest.raises(TypeError, match=msg): |
172 | 177 | index.astype(dtype)
|
173 | 178 |
|
174 | 179 | @pytest.mark.parametrize("subtype", ["datetime64[ns]", "timedelta64[ns]"])
|
|
0 commit comments