BUG: fix dtype of all-NaN MultiIndex level
State: closed

- [x] closes #17929
- [x] tests added / passed
- [x] passes `git diff master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

(This will need to be rebased on #17930 , but in the meanwhile it is useful for discussion)

An alternative, more radical, fix is to have ``pd.CategoricalIndex([np.nan]).dtype.categories`` float (currently object).

Labels:
name: MultiIndex
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=h1) Report
> Merging [#17934](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/77b4bb30ed5afc95f2c264c6b25e96ea8a9a5aee?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/17934/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17934      +/-   ##
==========================================
- Coverage   91.23%   91.22%   -0.02%     
==========================================
  Files         163      163              
  Lines       50113    50116       +3     
==========================================
- Hits        45723    45717       -6     
- Misses       4390     4399       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.03% <100%> (ø)` | :arrow_up: |
| #single | `40.32% <66.66%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.74% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17934?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/17934?src=pr&el=footer). Last update [77b4bb3...62ced7b](https://codecov.io/gh/pandas-dev/pandas/pull/17934?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/17934?src=pr&el=h1) Report
> Merging [#17934](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/5959ee3e133723136d4862864988a63ef3cc2a2f?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17934      +/-   ##
==========================================
+ Coverage   91.24%   91.24%   +<.01%     
==========================================
  Files         163      163              
  Lines       50091    50099       +8     
==========================================
+ Hits        45704    45715      +11     
+ Misses       4387     4384       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.05% <100%> (+0.02%)` | :arrow_up: |
| #single | `40.24% <55.55%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.79% <100%> (+0.04%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17934?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.2% <0%> (+1.81%)` | :arrow_up: |

------

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

> instead I would just defer to Index(values)

Unfortunately, this would work _only_ for all-NaN lists, since ``[3, np.nan]`` will result in a ``float64`` flat ``Index`` but in an ``int64`` level of ``MultiIndex``. Anyway...



> I would argue though that this should instead happen inside the Category

... I agree, done.

While I was at it I removed some obsolete warnings.
@jreback ping
@jreback : ping
thanks @toobaz