CLN: use self.dtype internally in Categorical
State: closed

Some clean-up that makes the code a bit easier to read IMO.

Labels:
name: Categorical
description: Categorical Data Type
name: Clean

Comments:
Hello @topper-123! Thanks for updating the PR.



Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on August 26, 2018 at 17:24 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22513?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@fa47b8d`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `71.42%`.

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

```diff
@@            Coverage Diff            @@
##             master   #22513   +/-   ##
=========================================
  Coverage          ?   92.03%           
=========================================
  Files             ?      169           
  Lines             ?    50780           
  Branches          ?        0           
=========================================
  Hits              ?    46737           
  Misses            ?     4043           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.44% <71.42%> (?)` | |
| #single | `42.22% <14.28%> (?)` | |

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

------

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

Ran ASV on benchmarks/categoricals.py. Result are varying a bit, which I attribute to randomness. For example:

```
      before           after         ratio
     [fa47b8d9]       [70ddcef7]
+          5.65μs           13.7μs     2.42  categoricals.CategoricalSlicing.time_getitem_list_like('monotonic_incr')
+          5.76ms           6.70ms     1.16  categoricals.CategoricalSlicing.time_getitem_bool_array('monotonic_incr')
+          3.42μs           3.91μs     1.14  categoricals.CategoricalSlicing.time_getitem_scalar('monotonic_decr')
+           610μs            689μs     1.13  categoricals.CategoricalSlicing.time_getitem_list('monotonic_decr')
-          6.12μs           5.55μs     0.91  categoricals.CategoricalSlicing.time_getitem_list_like('monotonic_decr')
-          6.46μs           5.65μs     0.88  categoricals.CategoricalSlicing.time_getitem_list_like('non_monotonic')
-          3.66μs           3.20μs     0.88  categoricals.CategoricalSlicing.time_getitem_scalar('monotonic_incr')
-          6.08ms           5.21ms     0.86  categoricals.CategoricalSlicing.time_getitem_bool_array('monotonic_decr')
-          4.66μs           4.00μs     0.86  categoricals.CategoricalSlicing.time_getitem_slice('non_monotonic')
-           729μs            567μs     0.78  categoricals.CategoricalSlicing.time_getitem_list('monotonic_incr')

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
```

and

```
      before           after         ratio
     [fa47b8d9]       [70ddcef7]
+          15.6ms           26.0ms     1.67  categoricals.CategoricalSlicing.time_getitem_bool_array('non_monotonic')
+           648μs            933μs     1.44  categoricals.CategoricalSlicing.time_getitem_list('monotonic_decr')
+           613μs            854μs     1.39  categoricals.CategoricalSlicing.time_getitem_list('monotonic_incr')
+          4.88μs           6.10μs     1.25  categoricals.CategoricalSlicing.time_getitem_list_like('monotonic_incr')
-          3.66μs           3.20μs     0.88  categoricals.CategoricalSlicing.time_getitem_scalar('monotonic_incr')
-          4.39μs           3.50μs     0.80  categoricals.CategoricalSlicing.time_getitem_scalar('non_monotonic')
-           729μs            539μs     0.74  categoricals.CategoricalSlicing.time_getitem_list('non_monotonic')
-          6.70ms           4.69ms     0.70  categoricals.CategoricalSlicing.time_getitem_bool_array('monotonic_incr')

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
```

Notice how ``categoricals.CategoricalSlicing.time_getitem_bool_array('monotonic_incr')`` in one run is slow (1.16) and th other fast (0.70).

Overall, I'd say this has is no significant effect on speed.
@TomAugspurger a look pls. lgtm to me.