Skip to content
Merged
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
5 changes: 2 additions & 3 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,9 +2128,8 @@ def _combined(self) -> IntervalSide:
)
comb = comb.view("complex128")[:, 0]
else:
comb = (np.array(left.ravel(), dtype="complex128")) + (
1j * np.array(right.ravel(), dtype="complex128")
)
comb = np.array(left.ravel(), dtype="complex128")
Copy link
Member

Choose a reason for hiding this comment

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

Could we use np.asarray? (NumPy might copy anyways but would be nice if it didn't in this case)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, but I believe it always makes a copy when going float64 -> complex128. I also tried

comb = np.empty(left.shape, dtype="complex128")
comb.real = left
comb.imag = right

but that had slightly worse performance than the identical np.array and np.asarray.

comb.imag = right.ravel()
return comb

def _from_combined(self, combined: np.ndarray) -> IntervalArray:
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/arrays/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ def test_unique_with_negatives(self):
)
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize(
"data",
[
[Interval(-np.inf, 0), Interval(-np.inf, 1)],
[Interval(0, np.inf), Interval(1, np.inf)],
],
)
def test_unique_with_infinty(self, data):
# https://github.com/pandas-dev/pandas/issues/63218
s = pd.Series(data)
tm.assert_interval_array_equal(s.unique(), s.array)
assert s.nunique() == 2
tm.assert_series_equal(s.drop_duplicates(), s)


class TestSetitem:
def test_set_na(self, left_right_dtypes):
Expand Down
Loading