Checking for length of categories before doing string conversion. fix…
State: closed

closes #11305


Labels:
name: Performance
description: Memory or execution speed performance
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: Categorical
description: Categorical Data Type

Comments:
- can you add a whats new note.
- pls add an asv benchmark (like your sample but only use 1000 categories)

can you update

Coming up. Had to read up where/how to do that. 

the categorical asv benchmark file breaks PEP8 302: 2 lines between functions. Should I correct? I searched but did not find a least of PEP8 errors the pandas decided to ignore.

@michaelaye that's ok for the PEP8 changes

I was able to start an `asv` run,  but for some reason, it only runs a python2.7 env, don't know why:

``` bash
$ asv continuous master HEAD -b categorical
· Creating environments
· Discovering benchmarks
·· Uninstalling from py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt
·· Building for py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt...................................
·· Installing into py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt..
· Running 12 total benchmarks (2 commits * 1 environments * 6 benchmarks)
[  0.00%] · For pandas commit hash cdff5bce:
[  0.00%] ·· Building for py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt.........................................
[  0.00%] ·· Benchmarking py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt
[  8.33%] ··· Running categoricals.categorical_constructor.time_fastpath                                4.85ms
[ 16.67%] ··· Running categoricals.categorical_constructor.time_regular_constructor                   226.53ms
[ 25.00%] ··· Running categoricals.categorical_rendering.time_rendering                                 2.31ms
[ 33.33%] ··· Running categoricals.categorical_value_counts.time_value_counts                          18.63ms
[ 41.67%] ··· Running categoricals.categorical_value_counts.time_value_counts_dropna                   24.74ms
[ 50.00%] ··· Running categoricals.concat_categorical.time_concat_categorical                          46.91ms
[ 50.00%] · For pandas commit hash c2aa6a23:
[ 50.00%] ·· Building for py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt......................................
[ 50.00%] ·· Benchmarking py2.7-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-scipy-sqlalchemy-xlrd-xlwt
[ 58.33%] ··· Running categoricals.categorical_constructor.time_fastpath                                4.93ms
[ 66.67%] ··· Running categoricals.categorical_constructor.time_regular_constructor                   210.66ms
[ 75.00%] ··· Running categoricals.categorical_rendering.time_rendering                                17.63ms
[ 83.33%] ··· Running categoricals.categorical_value_counts.time_value_counts                          13.60ms
[ 91.67%] ··· Running categoricals.categorical_value_counts.time_value_counts_dropna                   17.59ms
[100.00%] ··· Running categoricals.concat_categorical.time_concat_categorical                          50.98ms    before     after       ratio
  [c2aa6a23] [cdff5bce]
-   17.63ms     2.31ms      0.13  categoricals.categorical_rendering.time_rendering
SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
```

comments, then pls squash

merged via https://github.com/pydata/pandas/commit/47778004fbe2594d0f877fbf49b685ad55469557

thanks!