Skip to content

Commit 03c3239

Browse files
authored
REGR: Fix IntervalArray.nunique with infinity (#63267)
1 parent 772fd35 commit 03c3239

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

pandas/core/arrays/interval.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,9 +2128,8 @@ def _combined(self) -> IntervalSide:
21282128
)
21292129
comb = comb.view("complex128")[:, 0]
21302130
else:
2131-
comb = (np.array(left.ravel(), dtype="complex128")) + (
2132-
1j * np.array(right.ravel(), dtype="complex128")
2133-
)
2131+
comb = np.asarray(left.ravel(), dtype="complex128")
2132+
comb.imag = right.ravel()
21342133
return comb
21352134

21362135
def _from_combined(self, combined: np.ndarray) -> IntervalArray:

pandas/tests/arrays/interval/test_interval.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ def test_unique_with_negatives(self):
136136
)
137137
tm.assert_index_equal(result, expected)
138138

139+
@pytest.mark.parametrize(
140+
"data",
141+
[
142+
[Interval(-np.inf, 0), Interval(-np.inf, 1)],
143+
[Interval(0, np.inf), Interval(1, np.inf)],
144+
],
145+
)
146+
def test_unique_with_infinty(self, data):
147+
# https://github.com/pandas-dev/pandas/issues/63218
148+
s = pd.Series(data)
149+
tm.assert_interval_array_equal(s.unique(), s.array)
150+
assert s.nunique() == 2
151+
tm.assert_series_equal(s.drop_duplicates(), s)
152+
139153

140154
class TestSetitem:
141155
def test_set_na(self, left_right_dtypes):

0 commit comments

Comments
 (0)