BUG: fix MultiIndex.remove_unused_levels() when index contains NaNs
State: closed

- [x] closes #18417
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Missing-data
description: np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

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

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

```diff
@@            Coverage Diff             @@
##           master   #18426      +/-   ##
==========================================
- Coverage   91.35%   91.33%   -0.02%     
==========================================
  Files         163      163              
  Lines       49714    49722       +8     
==========================================
- Hits        45415    45414       -1     
- Misses       4299     4308       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.13% <100%> (ø)` | :arrow_up: |
| #single | `39.63% <0%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.42% <100%> (+0.02%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.8% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18426?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/18426?src=pr&el=footer). Last update [d421a09...6d1fcc1](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

> Please refer this.

Not following you, please explain (if this still applies).
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=h1) Report
> Merging [#18426](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/d421a09e382109c1bbe064107c4024b065839de2?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #18426      +/-   ##
==========================================
- Coverage   91.35%   91.33%   -0.02%     
==========================================
  Files         163      163              
  Lines       49714    49717       +3     
==========================================
- Hits        45415    45409       -6     
- Misses       4299     4308       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.13% <100%> (ø)` | :arrow_up: |
| #single | `39.63% <0%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.41% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.8% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18426?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/18426?src=pr&el=footer). Last update [d421a09...1ce45d0](https://codecov.io/gh/pandas-dev/pandas/pull/18426?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @toobaz