BUG: df.sort_values() not respecting na_position with categoricals #22556
State: closed

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


Labels:
name: Bug
name: Algos
description: Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
name: Categorical
description: Categorical Data Type

Comments:
Hello @staftermath! Thanks for updating the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/categorical.py`](https://github.com/staftermath/pandas/blob/7f6c68a721cd5bfe1e751f6a174d66dc0e61a346/pandas/core/arrays/categorical.py) !

 - There are no PEP8 issues in the file [`pandas/core/sorting.py`](https://github.com/staftermath/pandas/blob/7f6c68a721cd5bfe1e751f6a174d66dc0e61a346/pandas/core/sorting.py) !

 - There are no PEP8 issues in the file [`pandas/tests/frame/test_sorting.py`](https://github.com/staftermath/pandas/blob/7f6c68a721cd5bfe1e751f6a174d66dc0e61a346/pandas/tests/frame/test_sorting.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_stata.py`](https://github.com/staftermath/pandas/blob/7f6c68a721cd5bfe1e751f6a174d66dc0e61a346/pandas/tests/io/test_stata.py) !



##### Comment last updated on October 10, 2018 at 01:02 Hours UTC
**ci/circleci: py35_ascii**  failing related to this?: https://github.com/pandas-dev/pandas/issues/21763
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22640?src=pr&el=h1) Report
> Merging [#22640](https://codecov.io/gh/pandas-dev/pandas/pull/22640?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9285820d33d4986769a84f3db5f25cff8bf85d8d?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #22640      +/-   ##
==========================================
- Coverage   92.19%   92.18%   -0.01%     
==========================================
  Files         169      169              
  Lines       50954    50947       -7     
==========================================
- Hits        46975    46968       -7     
  Misses       3979     3979
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.28% <7.14%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22640?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/22640/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.53% <100%> (-0.1%)` | :arrow_down: |
| [pandas/core/sorting.py](https://codecov.io/gh/pandas-dev/pandas/pull/22640/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc29ydGluZy5weQ==) | `98.27% <100%> (+0.06%)` | :arrow_up: |

------

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

@WillAyd over to you
this looked ok, @WillAyd ?

@staftermath can you merge master
thanks @staftermath