Skip to content

BUG: pandas.Categorical.__unicode__ does not respect console display width #15380

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

Closed
wesm opened this issue Feb 12, 2017 · 3 comments
Closed
Labels
Bug Duplicate Report Duplicate issue or pull request

Comments

@wesm
Copy link
Member

wesm commented Feb 12, 2017

Code Sample, a copy-pastable example if possible

ages = [20, 22, 25, 27, 21, 23, 37, 31, 61, 45, 41, 32]
bins = [18, 25, 35, 60, 100]
cats = pd.cut(ages, bins)
print(repr(cats))

Problem description

This outputs

[(18, 25], (18, 25], (18, 25], (25, 35], (18, 25], ..., (25, 35], (60, 100], (35, 60], (35, 60], (25, 35]]
Length: 12
Categories (4, object): [(18, 25] < (25, 35] < (35, 60] < (60, 100]]

The first line has 106 characters. This is a bad user experience for shell users with 80-character-wide terminals

Expected Output

in the first line

[(18, 25], (18, 25], (18, 25], (25, 35], (18, 25], ...,
 (25, 35], (60, 100], (35, 60], (35, 60], (25, 35]]

or

[(18, 25], (18, 25], (18, 25], ..., (35, 60], (35, 60], (25, 35]]

Output of pd.show_versions()

pandas 0.19.2

@wesm wesm added the Bug label Feb 12, 2017
@wesm wesm added this to the 0.20.0 milestone Feb 12, 2017
@wesm
Copy link
Member Author

wesm commented Feb 12, 2017

The categories output spills over too

In [22]: data = np.random.randn(1000)

In [23]:  pd.qcut(data, [0, 0.1, 0.5, 0.9, 1.])
Out[23]: 
[(-1.245, 0.0321], (-1.245, 0.0321], (-1.245, 0.0321], (-1.245, 0.0321], (-1.245, 0.0321], ..., (0.0321, 1.286], (-1.245, 0.0321], (0.0321, 1.286], (0.0321, 1.286], (0.0321, 1.286]]
Length: 1000
Categories (4, object): [[-3.285, -1.245] < (-1.245, 0.0321] < (0.0321, 1.286] < (1.286, 3.117]]

@jreback
Copy link
Contributor

jreback commented Feb 12, 2017

dupe of #12066

@wesm
Copy link
Member Author

wesm commented Feb 12, 2017

Funny. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants