|
64 | 64 | from pandas.core.algorithms import (
|
65 | 65 | isin,
|
66 | 66 | take,
|
| 67 | + unique, |
67 | 68 | value_counts,
|
68 | 69 | )
|
69 | 70 | from pandas.core.arrays.base import (
|
@@ -1610,6 +1611,29 @@ def _combined(self) -> ArrayLike:
|
1610 | 1611 | comb = np.concatenate([left, right], axis=1)
|
1611 | 1612 | return comb
|
1612 | 1613 |
|
| 1614 | + def _from_combined(self, combined: np.ndarray) -> IntervalArray: |
| 1615 | + """ |
| 1616 | + Create a new IntervalArray with our dtype from a 1D complex128 ndarray. |
| 1617 | + """ |
| 1618 | + nc = combined.view("i8").reshape(-1, 2) |
| 1619 | + |
| 1620 | + dtype = self._left.dtype |
| 1621 | + if needs_i8_conversion(dtype): |
| 1622 | + new_left = type(self._left)._from_sequence(nc[:, 0], dtype=dtype) |
| 1623 | + new_right = type(self._right)._from_sequence(nc[:, 1], dtype=dtype) |
| 1624 | + else: |
| 1625 | + new_left = nc[:, 0].view(dtype) |
| 1626 | + new_right = nc[:, 1].view(dtype) |
| 1627 | + return self._shallow_copy(left=new_left, right=new_right) |
| 1628 | + |
| 1629 | + def unique(self) -> IntervalArray: |
| 1630 | + # Invalid index type "Tuple[slice, int]" for "Union[ExtensionArray, |
| 1631 | + # ndarray[Any, Any]]"; expected type "Union[int, integer[Any], slice, |
| 1632 | + # Sequence[int], ndarray[Any, Any]]" |
| 1633 | + nc = unique(self._combined.view("complex128")[:, 0]) # type: ignore[index] |
| 1634 | + nc = nc[:, None] |
| 1635 | + return self._from_combined(nc) |
| 1636 | + |
1613 | 1637 |
|
1614 | 1638 | def _maybe_convert_platform_interval(values) -> ArrayLike:
|
1615 | 1639 | """
|
|
0 commit comments