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

ENH: Option to configure line wrapping for columns #59564

Open
1 of 3 tasks
Nagidrop opened this issue Aug 20, 2024 · 4 comments
Open
1 of 3 tasks

ENH: Option to configure line wrapping for columns #59564

Nagidrop opened this issue Aug 20, 2024 · 4 comments
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement Output-Formatting __repr__ of pandas objects, to_string

Comments

@Nagidrop
Copy link

Nagidrop commented Aug 20, 2024

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

When having large enough display.max_colwidth value and a column contains cells with long data, other columns with shorter data will get their content (containing whitespaces) line-wrapped, even though there is plenty of space left and also a scrollbar to accommodate the large DataFrame width.

This can be reproduced using the snippet below:

import pandas as pd

pd.set_option('display.max_colwidth', None)  # None or a large enough value
df = pd.DataFrame({
    'column name': ['data0', 'data1'],
    'col2': ['0', 'a really longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg string']
})
display(df)

image

I want to make the column name shown on 1 line, instead of being line-wrapped to 2 lines. There isn't limited space here so I think linewrapping is unnecessary for such short data. I have searched in Pandas "Options and Settings" page) and there is currently no option to configure this behaviour. I would be really grateful if this gets implemented.

Feature Description

Add a new option to configure linewrapping behaviour for columns, e.g. display.linewrap that accepts boolean values, True to enable linewrapping and False otherwise.

Alternative Solutions

None

Additional Context

No response

@Nagidrop Nagidrop added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 20, 2024
@Nagidrop Nagidrop changed the title ENH: Option to configure line wrapping for column names ENH: Option to configure line wrapping for columns Aug 20, 2024
@rhshadrach
Copy link
Member

Thanks for the request. Why does the line wrapping cause an issue for you?

@rhshadrach rhshadrach added Needs Discussion Requires discussion from core team before further action Needs Info Clarification about behavior needed to assess issue Output-Formatting __repr__ of pandas objects, to_string and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 20, 2024
@Nagidrop
Copy link
Author

It could be my personal preference only, but I found reading things on 1 line is easier on my eyes. I have crafted an example for you to better illustrate. Here is some data when I use display.max_colwidth = 38:

image

Everything shows up nicely. But there is one review where it's very long (hence ellipsis) and I need to change display.max_colwidth = None to show all of its contents:

image

Now all of its contents are shown, but suddenly everything else is squished together and makes it hard to read, even though there is plenty of room left. The linewrapping behaviour here is unexpected because I only need the rightmost column to expand and show the long review. Also, when you specify a very large column width, logically it should show the column contents on 1 line, not condense and linewrap it (which is only appropriate if column width is small). That's why I think there should be an option to control this behaviour.

@rhshadrach
Copy link
Member

makes it hard to read

I can see the preference for not having line breaks, and could buy that with line breaks is harder, but I do not think this is hard to read. At a glance, it seems to me the additional complexity in output formatting is not worth the gain here.

If it could be shown that this change can be made with negligible additional complexity to the current set of features, I could be swayed otherwise.

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs and removed Needs Discussion Requires discussion from core team before further action Needs Info Clarification about behavior needed to assess issue labels Aug 21, 2024
@Nagidrop
Copy link
Author

Yeah the automatic linewrapping is generally a non-issue for me. Only in some occasions where it brings unexpected changes, I do feel like we could have some more control there. But if the option addition complicated the code base, I also agree to not implement at all.

Hopefully I could find a simple solution for this when I have some spare time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

2 participants