Get rid of MultiIndex conversion in IntervalIndex.is_unique
State: closed

-  xref #24813 
-  passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Actually, this modification doesn't improve the performance. But the code is more explanatory.


Labels:
name: Performance
description: Memory or execution speed performance
name: Interval
description: Interval data type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=h1) Report
> Merging [#25159](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/e3b095074c5c3b29ec25a994cd204349b872d961?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25159/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25159      +/-   ##
==========================================
- Coverage   92.37%   92.37%   -0.01%     
==========================================
  Files         166      166              
  Lines       52408    52408              
==========================================
- Hits        48412    48411       -1     
- Misses       3996     3997       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.79% <100%> (ø)` | :arrow_up: |
| #single | `42.86% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `95.25% <100%> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `88.04% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=footer). Last update [e3b0950...9c85d79](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=h1) Report
> Merging [#25159](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/6e0f9a971bcd07a4a6283dc03190b4363d42e292?src=pr&el=desc) will **decrease** coverage by `0.18%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25159/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25159      +/-   ##
==========================================
- Coverage   91.45%   91.27%   -0.19%     
==========================================
  Files         172      173       +1     
  Lines       52892    53002     +110     
==========================================
+ Hits        48373    48376       +3     
- Misses       4519     4626     +107
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.83% <100%> (-0.19%)` | :arrow_down: |
| #single | `41.76% <0%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `95.25% <100%> (ø)` | :arrow_up: |
| [pandas/compat/chainmap.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9jaGFpbm1hcC5weQ==) | `61.9% <0%> (-4.77%)` | :arrow_down: |
| [pandas/core/dtypes/cast.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Nhc3QucHk=) | `88.16% <0%> (-3.2%)` | :arrow_down: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `58.03% <0%> (-0.72%)` | :arrow_down: |
| [pandas/io/date\_converters.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2RhdGVfY29udmVydGVycy5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/compat/numpy/function.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9udW1weS9mdW5jdGlvbi5weQ==) | `87.91% <0%> (ø)` | :arrow_up: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.34% <0%> (ø)` | :arrow_up: |
| [pandas/compat/chainmap\_impl.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9jaGFpbm1hcF9pbXBsLnB5) | `0% <0%> (ø)` | |
| [pandas/core/strings.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3RyaW5ncy5weQ==) | `98.59% <0%> (ø)` | :arrow_up: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.69% <0%> (ø)` | :arrow_up: |
| ... and [13 more](https://codecov.io/gh/pandas-dev/pandas/pull/25159/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=footer). Last update [6e0f9a9...b382b17](https://codecov.io/gh/pandas-dev/pandas/pull/25159?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

does this affect perf at all? do we have an asv for this?
can you merge master and report on the asv's for this (and add if needbe)
As jschendel said, this change slowed down the performance. IntervalArray.unique and algo.unique also convert to an array of Interval in the first place.
```

All benchmarks:

       before           after         ratio
     [33f91d8f]       [9c23aac9]
     <master>         <is_unique>
+         249±4ns          378±3ms 1519132.92  index_object.IntervalIndexMethod.time_is_unique
```
@makbigc the asv's that you added look good. can you remove the actual perf change.
I wrote a new `IntervalIndex.is_unique` which did improve the performance.

```
All benchmarks:

       before           after         ratio
     [33f91d8f]       [b382b173]
     <v0.24.0~79>       <is_unique>
-         249±4ns        113±0.5ns     0.45  index_object.IntervalIndexMethod.time_is_unique
```
can you merge master and update
can you merge master
I broke something when merging. This PR is continued in #26391