BUG: DataFrame repr honors display.width with max_columns=0 (GH#21337)#66004
Draft
jbrockmendel wants to merge 1 commit into
Draft
BUG: DataFrame repr honors display.width with max_columns=0 (GH#21337)#66004jbrockmendel wants to merge 1 commit into
jbrockmendel wants to merge 1 commit into
Conversation
When display.max_columns was 0 (the default), the repr's horizontal-fit logic re-read the terminal width via shutil.get_terminal_size() and ignored an explicitly set display.width. The width option is now honored: the display.width default becomes None (auto-detect when interactive, no truncation in non-interactive sessions), and both the string- and format-level fit paths use the resolved width instead of the raw terminal size. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #21337
When
display.max_columnsis0(the default since 0.23), theDataFrame.__repr__horizontal-fit logic re-read the physical terminal width viashutil.get_terminal_size()and ignored an explicitly setdisplay.width. This was a regression from the 0.22→0.23 change of themax_columnsdefault from 20 to 0; themax_columns > 0path already honored the width.Changes:
display.widthnow defaults toNone, matching its documented "set to None to auto-detect" semantics. The terminal width is auto-detected in interactive sessions, and wide output is no longer truncated in non-interactive sessions (scripts, redirected output)._fit_strcols_to_terminal_width) and format-level (_calc_max_cols_fitted) fit paths now use the resolved width (line_width/get_console_size()) instead of re-reading the raw terminal size.get_console_sizekeeps an 80-column fallback, since a width cannot be auto-detected there.This also activates the previously-dead auto-detect branch in
DataFrame._repr_fits_horizontal_that its own comments describe (thedisplay.width is not Nonecheck now correctly means "user set an explicit width"). A regression test is added; the only pre-existing tests affected were two intest_format.py, updated accordingly.