Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Categorical repr can exceed options.display.width #12066

Open
wesm opened this issue Jan 17, 2016 · 4 comments
Open

BUG: Categorical repr can exceed options.display.width #12066

wesm opened this issue Jan 17, 2016 · 4 comments
Labels
Bug Categorical Categorical Data Type Output-Formatting __repr__ of pandas objects, to_string

Comments

@wesm
Copy link
Member

wesm commented Jan 17, 2016

I see in the tests things like test_categorical_repr_datetime which exceeds the 80-character display width. This doesn't seem right to me, but want to check whether I'm missing something.

xref #15380

@wesm
Copy link
Member Author

wesm commented Jan 17, 2016

pandas/tests/test_categorical.py is a bloodbath because of this, so I'm going to disable flake8 checks in that file until this issue can be addressed.

@wesm wesm added this to the 0.18.0 milestone Jan 17, 2016
@wesm wesm added the Bug label Jan 17, 2016
@jreback
Copy link
Contributor

jreback commented Jan 17, 2016

In [9]: pd.set_option('display.width',120)
yeh I don't think the actual raw Categorical was repr was setup to limit printing, with the exception of the number of categories via display.max_categories

c = pd.Categorical(pd.date_range('20130101 09:00:00',periods=10))

In [10]: c
Out[10]: 
[2013-01-01 09:00:00, 2013-01-02 09:00:00, 2013-01-03 09:00:00, 2013-01-04 09:00:00, 2013-01-05 09:00:00, 2013-01-06 09:00:00, 2013-01-07 09:00:00, 2013-01-08 09:00:00, 2013-01-09 09:00:00, 2013-01-10 09:00:00]
Categories (10, datetime64[ns]): [2013-01-01 09:00:00, 2013-01-02 09:00:00, 2013-01-03 09:00:00, 2013-01-04 09:00:00, ..., 2013-01-07 09:00:00,
                                  2013-01-08 09:00:00, 2013-01-09 09:00:00, 2013-01-10 09:00:00]

In [11]: pd.set_option('display.width',80)

In [12]: c
Out[12]: 
[2013-01-01 09:00:00, 2013-01-02 09:00:00, 2013-01-03 09:00:00, 2013-01-04 09:00:00, 2013-01-05 09:00:00, 2013-01-06 09:00:00, 2013-01-07 09:00:00, 2013-01-08 09:00:00, 2013-01-09 09:00:00, 2013-01-10 09:00:00]
Categories (10, datetime64[ns]): [2013-01-01 09:00:00, 2013-01-02 09:00:00, 2013-01-03 09:00:00,
                                  2013-01-04 09:00:00, ..., 2013-01-07 09:00:00, 2013-01-08 09:00:00,
                                  2013-01-09 09:00:00, 2013-01-10 09:00:00]

In [13]: pd.set_option('display.max_categories',4)

In [14]: c
Out[14]: 
[2013-01-01 09:00:00, 2013-01-02 09:00:00, 2013-01-03 09:00:00, 2013-01-04 09:00:00, 2013-01-05 09:00:00, 2013-01-06 09:00:00, 2013-01-07 09:00:00, 2013-01-08 09:00:00, 2013-01-09 09:00:00, 2013-01-10 09:00:00]
Categories (10, datetime64[ns]): [2013-01-01 09:00:00, 2013-01-02 09:00:00, ..., 2013-01-09 09:00:00,
                                  2013-01-10 09:00:00]

The index printer had a bit more effort

In [15]: pd.CategoricalIndex(c)
Out[15]: 
CategoricalIndex(['2013-01-01 09:00:00', '2013-01-02 09:00:00',
                  '2013-01-03 09:00:00', '2013-01-04 09:00:00',
                  '2013-01-05 09:00:00', '2013-01-06 09:00:00',
                  '2013-01-07 09:00:00', '2013-01-08 09:00:00',
                  '2013-01-09 09:00:00', '2013-01-10 09:00:00'],
                 categories=[2013-01-01 09:00:00, 2013-01-02 09:00:00, 2013-01-03 09:00:00, 2013-01-04 09:00:00, ...], ordered=False, dtype='category')

@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Jan 17, 2016
@jreback jreback modified the milestones: 0.18.1, 0.18.0 Feb 10, 2016
@jreback jreback modified the milestones: 0.18.2, 0.18.1 Apr 18, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, 0.19.0 Aug 19, 2016
@wesm wesm modified the milestones: 0.20.0, Next Major Release Feb 12, 2017
@wesm
Copy link
Member Author

wesm commented Feb 12, 2017

I marked for 0.20. If someone else who is closer to the current Categorical code doesn't get to it, please bug me and I'll write a patch. Thanks

@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
jreback pushed a commit that referenced this issue Apr 2, 2017
Another round of house-cleaning that builds off #15842.    xref <a
href="https://github.com/pandas-
dev/pandas/issues/12066#issuecomment-172285473">#12066  (comment)</a>
: the issue remains unresolved, but it does not seem entirely
necessary to disable style-checking on the entire file for that IMO.

Author: gfyoung <gfyoung17@gmail.com>

Closes #15867 from gfyoung/flake8-noqa-clean and squashes the following commits:

0c84926 [gfyoung] CLN: Make tseries/common.py flake8-able
7a799ff [gfyoung] CLN: Make _version.py flake8-able
7087b64 [gfyoung] CLN: Make test_categorical.py flake8-able
5d5abf8 [gfyoung] CLN: Make test_categorical.py flake8-able
6ace90b [gfyoung] CLN: Make test_eval.py flake8-able
@kurtqq
Copy link

kurtqq commented Jun 15, 2019

@wesm Do you plan to fix this bug ?

@mroeschke mroeschke added Categorical Categorical Data Type and removed good first issue labels Apr 21, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants