BUG: fixed wrong order of ordered labels in pd.cut()
State: closed

 - [x] closes #16459 
 - [x] tests added / passed
 - [x] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [ ] whatsnew entry

Changes to how `cut` instantiates `Categorical` when a list of labels are passed to it, and the `test_cut_pass_labels` test for it. If labels are passed in as a `Categorical` already, behavior isn't altered at all, but if the user specifies a list of labels, the rank ordering of those labels is preserved in `cut`.


Labels:
name: Bug
name: Blocker
description: Blocking issue or pull request for an upcoming release
name: Categorical
description: Categorical Data Type

Comments:
@jreback happy to do  that, can you tell me how/where to add the what's new, and what you're looking for in terms of the original test? all i know is it passes.
doc/source/whatsnew/v0.20.2.txt

you copy the test from the original issue and assert that it is correct now (you construct the expected) and compare vs running ``pd.cut``. it should fail w/o this fix and pass with it.
Ok, the what's new is straightforward, in terms of the test, do you just want me to include the output in the original issue? or an actual test in `test_tile.py`? The test that was failing no longer fails.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=h1) Report
> Merging [#16466](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/04356a83c0dc8a749c84e168535e6673f2548ec6?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@           Coverage Diff           @@
##           master   #16466   +/-   ##
=======================================
  Coverage   90.42%   90.42%           
=======================================
  Files         161      161           
  Lines       51027    51027           
=======================================
  Hits        46142    46142           
  Misses       4885     4885
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.26% <100%> (ø)` | :arrow_up: |
| #single | `40.17% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/reshape/tile.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS90aWxlLnB5) | `90.25% <100%> (ø)` | :arrow_up: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #16466      +/-   ##
==========================================
+ Coverage   90.75%   90.79%   +0.04%     
==========================================
  Files         161      161              
  Lines       51073    51063      -10     
==========================================
+ Hits        46350    46365      +15     
+ Misses       4723     4698      -25
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.63% <100%> (+0.04%)` | :arrow_up: |
| #single | `40.15% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/reshape/tile.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS90aWxlLnB5) | `90.25% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.56% <0%> (-0.09%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `92.26% <0%> (-0.05%)` | :arrow_down: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `93.06% <0%> (-0.05%)` | :arrow_down: |
| [pandas/core/window.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvd2luZG93LnB5) | `96.48% <0%> (-0.02%)` | :arrow_down: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.66% <0%> (-0.01%)` | :arrow_down: |
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.04% <0%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.66% <0%> (ø)` | :arrow_up: |
| [pandas/core/reshape/pivot.py](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9waXZvdC5weQ==) | `95.08% <0%> (ø)` | :arrow_up: |
| ... and [4 more](https://codecov.io/gh/pandas-dev/pandas/pull/16466?src=pr&el=tree-more) | |

------

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

> in the original issue? or an actual test in test_tile.py? The test that was failing no longer fails.

that's exactly the point. the test should succeed now! and failed before the fix.
Pre-fix:
```
In [2]: labels = ['okay', 'good', 'bad']
In [3]: pd.cut([.2, .4, .6, 1, 2, 3, 5], 3, labels=labels)

Out [3]:
[okay, okay, okay, okay, good, good, bad]
Categories (3, object): [bad < good < okay]
```

Post-fix:
```
In [4]: labels = ['okay', 'good', 'bad']
In [5]: pd.cut([.2, .4, .6, 1, 2, 3, 5], 3, labels=labels)

Out [5]:
[okay, okay, okay, okay, good, good, bad]
Categories (3, object): [okay < good < bad]
```

```pytest reshape/test_tile.py
=========================================================================================== test session starts ============================================================================================
platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/economy/Documents/pycon-2017/pandas/pandas, inifile: setup.cfg
collected 35 items

reshape/test_tile.py ...................................

======================================================================================== 35 passed in 0.58 seconds =========================================================================================
```
@economy so make a test out of that.
Gotcha, sorry for the confusion.
@jreback finally had a chance to get to this. should be green now
@economy looks like a conflict in the whatsnew file. Can you rebase?
thanks!