Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ def from_arrays(
copy: bool = False,
dtype: Dtype | None = None,
) -> IntervalIndex:
# Check for mismatched signed/unsigned integer dtypes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would make more sense to do this on the IntervalArray.from_arrays method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will update changes in IntervalArray.from_arrays

left_dtype = getattr(left, "dtype", None)
right_dtype = getattr(right, "dtype", None)
if (
left_dtype is not None
and right_dtype is not None
and left_dtype.kind in "iu"
and right_dtype.kind in "iu"
and left_dtype.kind != right_dtype.kind
):
raise TypeError(
f"Left and right arrays must have matching signedness. "
f"Got {left_dtype} and {right_dtype}."
)
with rewrite_exception("IntervalArray", cls.__name__):
array = IntervalArray.from_arrays(
left, right, closed, copy=copy, dtype=dtype
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,14 @@ def test_is_all_dates(self):
assert not year_2017_index._is_all_dates


def test_from_arrays_mismatched_signedness_raises():
# GH 55715
left = np.array([0, 1, 2], dtype="int64")
right = np.array([1, 2, 3], dtype="uint64")
with pytest.raises(TypeError, match="matching signedness"):
IntervalIndex.from_arrays(left, right)


def test_dir():
# GH#27571 dir(interval_index) should not raise
index = IntervalIndex.from_arrays([0, 1], [1, 2])
Expand Down
Loading