Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions pandas/tests/indexes/interval/test_astype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import numpy as np
import pytest

Expand Down Expand Up @@ -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]"])
Expand Down