diff --git a/asv_bench/benchmarks/index_object.py b/asv_bench/benchmarks/index_object.py index bbe164d4858ab..0d72285685314 100644 --- a/asv_bench/benchmarks/index_object.py +++ b/asv_bench/benchmarks/index_object.py @@ -1,7 +1,7 @@ import numpy as np import pandas.util.testing as tm from pandas import (Series, date_range, DatetimeIndex, Index, RangeIndex, - Float64Index) + Float64Index, IntervalIndex) class SetOperations(object): @@ -181,4 +181,16 @@ def time_get_loc(self): self.ind.get_loc(0) +class IntervalIndexMethod(object): + # GH 24813 + def setup(self): + N = 10**5 + left = np.append(np.arange(N), np.array(0)) + right = np.append(np.arange(1, N + 1), np.array(1)) + self.intv = IntervalIndex.from_arrays(left, right) + + def time_is_unique(self): + self.intv.is_unique + + from .pandas_vb_common import setup # noqa: F401 diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index ccf5c43280765..8a7d681a8f81f 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -177,6 +177,7 @@ Performance Improvements - Improved performance of :meth:`pandas.core.groupby.GroupBy.quantile` (:issue:`20405`) - Improved performance of :meth:`read_csv` by faster tokenizing and faster parsing of small float numbers (:issue:`25784`) - Improved performance of :meth:`read_csv` by faster parsing of N/A and boolean values (:issue:`25804`) +- Improved performance of :meth:`IntervalIndex.is_unique` by removing conversion to `MultiIndex` (:issue:`24813`) .. _whatsnew_0250.bug_fixes: diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 2c63fe33c57fe..d9ee5d9433a5b 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -463,7 +463,13 @@ def is_unique(self): """ Return True if the IntervalIndex contains unique elements, else False """ - return self._multiindex.is_unique + left = self.values.left + right = self.values.right + for i in range(len(self)): + mask = (left[i] == left) & (right[i] == right) + if mask.sum() > 1: + return False + return True @cache_readonly @Appender(_interval_shared_docs['is_non_overlapping_monotonic']