Let _get_dtype accept Categoricals and CategoricalIndex 
State: closed

 - [ x] closes #16817
 - [x ] tests added / passed
 - [x ] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff`` (On Windows, ``git diff upstream/master -u -- "*.py" | flake8 --diff`` might work as an alternative.)
 - [ ] whatsnew entry

Makes ``_get_dtype`` accept ``Categorical``s and ``CategoricalIndex``. Also passes relevant tests in ``test_common.py``.

See also discussion in #16845. Is there a manual for checking performance (can't imagine this affects performance, though)?

Labels:
name: Dtype Conversions
description: Unexpected or buggy dtype conversions
name: Compat
description: pandas objects compatability with Numpy or Python functions
name: Categorical
description: Categorical Data Type

Comments:
> See also discussion in #16845. Is there a manual for checking performance (can't imagine this affects performance, though)?

This is in a critical path for lots of things. This absolutely needs checking.

http://pandas.pydata.org/pandas-docs/stable/contributing.html#running-the-performance-test-suite


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

```diff
@@            Coverage Diff             @@
##           master   #16887      +/-   ##
==========================================
+ Coverage   90.96%   90.97%   +<.01%     
==========================================
  Files         161      161              
  Lines       49301    49303       +2     
==========================================
+ Hits        44849    44853       +4     
+ Misses       4452     4450       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.74% <100%> (+0.02%)` | :arrow_up: |
| #single | `40.19% <50%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16887?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/16887?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbW1vbi5weQ==) | `94.81% <100%> (+0.02%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16887?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16887?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.71% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/16887?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.23% <0%> (-0.1%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/16887?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.05% <0%> (+1.81%)` | :arrow_up: |

------

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

Alright, I've run asv. It took 2 hours, and the results are all over the place, from ratios of over 3 down to 0.01.  I assume this is not normal.

I tried selectively running the worst offenders individually, and then the results were now within limits (``BENCHMARKS NOT SIGNIFICANTLY CHANGED``). Do I need to take special precautions when running the whole suite, to avoid affecting the results?

ok on the asv. thanks for running that. just needs a whatsnew note. ping on green.
thanks @topper-123