Repository: pandas-dev/pandas
File: pandas/core/arrays/interval.py (Python)

Code before:
    def _from_combined(self, combined: np.ndarray) -> IntervalArray:
        """
        Create a new IntervalArray with our dtype from a 1D complex128 ndarray.
        """
        nc = combined.view("i8").reshape(-1, 2)

        dtype = self._left.dtype
        if needs_i8_conversion(dtype):
            assert isinstance(self._left, (DatetimeArray, TimedeltaArray))
            new_left: DatetimeArray | TimedeltaArray | np.ndarray = type(
                self._left
            )._from_sequence(nc[:, 0], dtype=dtype)
            assert isinstance(self._right, (DatetimeArray, TimedeltaArray))
            new_right: DatetimeArray | TimedeltaArray | np.ndarray = type(
                self._right
            )._from_sequence(nc[:, 1], dtype=dtype)
        else:
            assert isinstance(dtype, np.dtype)
            new_left = nc[:, 0].view(dtype)
            new_right = nc[:, 1].view(dtype)
        return self._shallow_copy(left=new_left, right=new_right)

    def unique(self) -> IntervalArray:
        # No overload variant of "__getitem__" of "ExtensionArray" matches argument
        # type "Tuple[slice, int]"
        if needs_i8_conversion(self._left.dtype):
            nc = unique(
                self._combined.view("complex128")[:, 0]  # type: ignore[call-overload]
            )
        else:
            nc = unique(
                # Using .view("complex128") with negatives causes issues.
                # GH#61917
                (np.array(self._combined[:, 0], dtype=complex))
                + (1j * np.array(self._combined[:, 1], dtype=complex))
            )
        nc = nc[:, None]
        return self._from_combined(nc)


def _maybe_convert_platform_interval(values) -> ArrayLike:
    """
    Try to do platform conversion, with special casing for IntervalArray.
    Wrapper around maybe_convert_platform that alters the default return
    dtype in certain cases to be compatible with IntervalArray.  For example,
    empty lists return with integer dtype instead of object dtype, which is
    prohibited for IntervalArray.

    Parameters
    ----------
    values : array-like

Review comment (bug):
The reason I kept this is because [this test](https://github.com/pandas-dev/pandas/blob/e72c8a1e0ad421c1b8a7b918d995f24bed595cc3/pandas/tests/series/methods/test_unique.py#L62) was failing with the new approach.

Code after:
            assert not isinstance(self._right, np.ndarray)
            new_right = self._right.delete(loc)
        return self._shallow_copy(left=new_left, right=new_right)

    def repeat(
        self,
        repeats: int | Sequence[int],
        axis: AxisInt | None = None,
    ) -> Self:
        """
        Repeat elements of a IntervalArray.

        Returns a new IntervalArray where each element of the current IntervalArray
        is repeated consecutively a given number of times.

        Parameters
        ----------
        repeats : int or array of ints
            The number of repetitions for each element. This should be a
            non-negative integer. Repeating 0 times will return an empty
            IntervalArray.
        axis : None
            Must be ``None``. Has no effect but is accepted for compatibility
            with numpy.

        Returns
        -------
        IntervalArray
            Newly created IntervalArray with repeated elements.

        See Also
        --------
        Series.repeat : Equivalent function for Series.
        Index.repeat : Equivalent function for Index.
        numpy.repeat : Similar method for :class:`numpy.ndarray`.
        ExtensionArray.take : Take arbitrary positions.

        Examples
        --------
        >>> cat = pd.Categorical(["a", "b", "c"])
        >>> cat
        ['a', 'b', 'c']
        Categories (3, str): ['a', 'b', 'c']
        >>> cat.repeat(2)
        ['a', 'a', 'b', 'b', 'c', 'c']
        Categories (3, str): ['a', 'b', 'c']
        >>> cat.repeat([1, 2, 3])
        ['a', 'b', 'b', 'c', 'c', 'c']
        Categories (3, str): ['a', 'b', 'c']
        """
        nv.validate_repeat((), {"axis": axis})