BUG: Categorical(Index) passed as categories
State: closed

- [x] closes #17884
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

@TomAugspurger I am not sure we had a discussion about that before, but to me it does not make many sense to have a CategoricalIndex as the categories of a Categorical/CategoricalIndex, so I think we should convert passed categories (which is what this PR is doing). 
Alternative to fix #17884 is to fix the repr code to deal with Categorical categories.

Labels:
name: Categorical
description: Categorical Data Type

Comments:
Thanks Joris, agreed with the changes here. Looks like this conflicts with your fastpath PR.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=h1) Report
> Merging [#17888](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9092445b1b8bdc6cb031a2319ac98204b13f908c?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/17888/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17888      +/-   ##
==========================================
- Coverage   91.23%   91.22%   -0.02%     
==========================================
  Files         163      163              
  Lines       50105    50103       -2     
==========================================
- Hits        45714    45704      -10     
- Misses       4391     4399       +8
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.03% <100%> (ø)` | :arrow_up: |
| #single | `40.31% <83.33%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `95.15% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.5% <0%> (+0.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17888?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/17888?src=pr&el=footer). Last update [9092445...ab23d41](https://codecov.io/gh/pandas-dev/pandas/pull/17888?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/17888?src=pr&el=h1) Report
> Merging [#17888](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9092445b1b8bdc6cb031a2319ac98204b13f908c?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/17888/graphs/tree.svg?token=eZ4WkYLtcO&width=650&src=pr&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17888      +/-   ##
==========================================
- Coverage   91.23%   91.22%   -0.02%     
==========================================
  Files         163      163              
  Lines       50105    50105              
==========================================
- Hits        45714    45706       -8     
- Misses       4391     4399       +8
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.03% <100%> (ø)` | :arrow_up: |
| #single | `40.31% <83.33%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `95.14% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17888?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.5% <0%> (+0.09%)` | :arrow_up: |

------

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

One disadvantage of the my changes is that is somehow relaxes the "unique" requirement for the passed categories. Because now you can pass a non-unique Categorical, and we don't raise anymore but just take its unique categories. 
I think it seems obvious that this is what the user want, but still, I am not sure relaxing the requirement is a good idea (eg in `from_codes` it means the passed codes don't match exactly the passed categories). But actually I can easily check this by moving the check for Categorical values after the check for unique / nulls. 
@jorisvandenbossche ping when updated.
As far as I am concerned, this is updated. Is there a comment I overlooked?