BUG: preserve name in set_categories (#17509)
State: closed

- [x] closes #17509
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Categorical
description: Categorical Data Type

Comments:
Also, if you could add new tests to ensure the name is passed through, and a release note in doc/source/whatsnew/v0.21.0.txt under bug fixes.
Hello @Giftlin! Thanks for updating the PR.





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

##### Comment last updated on September 18, 2017 at 11:36 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=h1) Report
> Merging [#17517](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f11bbf2f505d81900cc83ce387a6a1b1d2a2f866?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/17517/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17517      +/-   ##
==========================================
- Coverage   91.18%   91.16%   -0.02%     
==========================================
  Files         163      163              
  Lines       49543    49544       +1     
==========================================
- Hits        45177    45169       -8     
- Misses       4366     4375       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.95% <100%> (ø)` | :arrow_up: |
| #single | `40.21% <75%> (-0.06%)` | :arrow_down: |

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

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17517?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/17517?src=pr&el=footer). Last update [f11bbf2...b817366](https://codecov.io/gh/pandas-dev/pandas/pull/17517?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/17517?src=pr&el=h1) Report
> Merging [#17517](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/328c7e179b72e257e27adf92a06718fd5a40473f?src=pr&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17517      +/-   ##
==========================================
- Coverage   91.25%    91.2%   -0.05%     
==========================================
  Files         163      163              
  Lines       49606    49625      +19     
==========================================
- Hits        45266    45261       -5     
- Misses       4340     4364      +24
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.99% <100%> (-0.03%)` | :arrow_down: |
| #single | `40.19% <75%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.57% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.23% <0%> (-1.82%)` | :arrow_down: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `97% <0%> (-0.18%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.77% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `93.57% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.53% <0%> (ø)` | :arrow_up: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/resample.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzYW1wbGUucHk=) | `96.17% <0%> (+0.01%)` | :arrow_up: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `82.73% <0%> (+0.03%)` | :arrow_up: |
| ... and [1 more](https://codecov.io/gh/pandas-dev/pandas/pull/17517?src=pr&el=tree-more) | |

------

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

contrib docs are [here](http://pandas.pydata.org/pandas-docs/stable/contributing.html). pls add tests IN this PR. It should fail with the tests, then pass after the fix.
@Giftlin FYI you don't need to push after every commit. you can still make seperate commits, but uless its an isolated change, this just runs the CI more.
@jreback thanks for d info. :) 
I'm very new here. 13 days old . Haven't gotten used to yet. 
> I'm very new here. 13 days old . Haven't gotten used to yet.

np. thanks for the contributions! you are doing great!
@jreback , tests passed. Is the test function fine? Or I should parameterize it?
parameteize 
and u have some lint issues
ok this looks fine to me (after fixing linting). ping on green.
@jreback
@TomAugspurger 
checks have passed
@Giftlin Thanks! 

(I added a small commit with some white-space clean-up. Not sure what went wrong, but the diff showed changes in whitespace on some lines. You might need to check the settings of your editor to ensure it only uses spaces for whitespace)