Rank categorical
State: closed

check for categorical, and then pass the underlying integer codes.

 - [ ] closes #15420
 - [ ] tests added / passed
 - [ ] passes ``git diff upstream/master | flake8 --diff``
 - [ ] whatsnew entry


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

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/15422?src=pr&el=h1) Report
> Merging [#15422](https://codecov.io/gh/pandas-dev/pandas/pull/15422?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/81c57e20da278494dfebc2f1043f5ff361a234f3?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.


```diff
@@            Coverage Diff             @@
##           master   #15422      +/-   ##
==========================================
+ Coverage   90.36%   90.36%   +<.01%     
==========================================
  Files         136      136              
  Lines       49532    49543      +11     
==========================================
+ Hits        44760    44771      +11     
  Misses       4772     4772
```


| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/15422?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/compare/81c57e20da278494dfebc2f1043f5ff361a234f3...a7e573bb2dbbd9f06aebb5e5aa83dc553d7cdae6?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.48% <100%> (+0.01%)` | :white_check_mark: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/compare/81c57e20da278494dfebc2f1043f5ff361a234f3...a7e573bb2dbbd9f06aebb5e5aa83dc553d7cdae6?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `96.91% <100%> (+0.04%)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/15422?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/15422?src=pr&el=footer). Last update [81c57e2...a7e573b](https://codecov.io/gh/pandas-dev/pandas/compare/81c57e20da278494dfebc2f1043f5ff361a234f3...a7e573bb2dbbd9f06aebb5e5aa83dc553d7cdae6?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
@jreback I have added tests for testing na_option and descending arguments to rank function. All tests are passing.
Moved rank function as method inside categoricals. Added additional tests in tests/series/test_analytics though i feel these tests should reside in tests/test_categoricals
created private method _rank instead of public rank method.
 _rank returns ndarray and accepts *args and **kwargs. 
_rank uses the rank function from pandas.core.algorithms

Sorry for the delay. Got caught up with work. _values_for_rank works as asked.  Hopefully this solves the problem in an acceptable way.
@ikilledthecat something went wrong with a rebase I think. Can you rebase again against latest master and push again?

```
git fetch upstream
git checkout rank_categorical
git rebase upstream/master
git push -f origin rank_categorical
```
rebased against latest master
@ikilledthecat 2 small comments. ping on all green.
@jreback changes done!! thanks for the help and patience!
thanks @ikilledthecat 

note that for the perf issues, might have to slightly reorg the code (meaning that ``_values_for_rank`` would need to be passed the ``.rank()`` params