Skip to content

Commit

Permalink
TST: GH38718 fix an xfail test and add new test for expected behaviou…
Browse files Browse the repository at this point in the history
…r when casting interval range from float to int (pandas-dev#38719)
  • Loading branch information
moink authored and luckyvs1 committed Jan 20, 2021
1 parent f3476a4 commit 00ae71c
Showing 1 changed file with 17 additions and 12 deletions.
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

0 comments on commit 00ae71c

Please sign in to comment.