BUG: Empty CategoricalIndex fails with boolean categories
State: closed

Fixes #22702.

This bug was introduced in [7818486859d1aba53](https://github.com/pandas-dev/pandas/commit/7818486859d1aba53ce359b93cfc772e688958e5); per [my comment](https://github.com/pandas-dev/pandas/issues/22702#issuecomment-421364087), the problem is here:

```python
    if not is_dtype_equal(values.dtype, categories.dtype):
        values = ensure_object(values)
        categories = ensure_object(categories)

    (hash_klass, vec_klass), vals = _get_data_algo(values, _hashtables)
    (_, _), cats = _get_data_algo(categories, _hashtables)
```

When `categories` is `Index([True], dtype='object')` and `values` is `array([], dtype='object')`, the `ensure_object` call is bypassed, but in `_get_data_algo`, an `Index` consisting entirely of boolean objects will be coerced to `uint64`, which violates the assumption that `values` and `categories` have the same dtype.

I felt that retrieving the underlying numpy arrays (if any exist) is the safest way to handle this without having too many wide-reaching effects across the rest of the codebase, but there might be a better way to enforce that these are not coerced into different data types.

- [x] closes #xxxx
- [x] tests added 
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Dtype Conversions
description: Unexpected or buggy dtype conversions
name: Categorical
description: Categorical Data Type

Comments:
Hello @pganssle! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/categorical.py`](https://github.com/pganssle/pandas/blob/ad4155d2b2df554524455b85ed951459b423c1f7/pandas/core/arrays/categorical.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/categorical/test_constructors.py`](https://github.com/pganssle/pandas/blob/ad4155d2b2df554524455b85ed951459b423c1f7/pandas/tests/arrays/categorical/test_constructors.py) !


I've pushed new changes that address all comments (though I did not switch over to `asarray`).
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22710?src=pr&el=h1) Report
> Merging [#22710](https://codecov.io/gh/pandas-dev/pandas/pull/22710?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/40dfadd02fa564434323007240d48b57068eea25?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/22710/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22710?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22710      +/-   ##
==========================================
+ Coverage   92.17%   92.17%   +<.01%     
==========================================
  Files         169      169              
  Lines       50769    50771       +2     
==========================================
+ Hits        46798    46800       +2     
  Misses       3971     3971
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.59% <100%> (ø)` | :arrow_up: |
| #single | `42.32% <100%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22710?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/22710/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.75% <100%> (+0.01%)` | :arrow_up: |

------

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

All issues should be addressed now. I'm guessing the azure pipeline failure is unrelated. I can rebase against master if it's fixed in master.
Currently working on the azure stuff, you can safely ignore it.

On Wed, Sep 19, 2018 at 9:04 AM Paul Ganssle <notifications@github.com>
wrote:

> All issues should be addressed now. I'm guessing the azure pipeline
> failure is unrelated. I can rebase against master if it's fixed in master.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/22710#issuecomment-422816559>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIohEDLZwgt4Tp5nbgJeV3EhVf8sHks5uck7ogaJpZM4WpVL2>
> .
>

lgtm. merging after azure updates by @TomAugspurger 
Sorry about all the noise, your PR is my guinea pig :)

Things should be OK now. Ping on green.
@TomAugspurger Green now.
Thanks!