Skip to content

BUG: DataFrame repr honors display.width with max_columns=0 (GH#21337)#66004

Draft
jbrockmendel wants to merge 1 commit into
pandas-dev:mainfrom
jbrockmendel:bug-21337
Draft

BUG: DataFrame repr honors display.width with max_columns=0 (GH#21337)#66004
jbrockmendel wants to merge 1 commit into
pandas-dev:mainfrom
jbrockmendel:bug-21337

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

closes #21337

When display.max_columns is 0 (the default since 0.23), the DataFrame.__repr__ horizontal-fit logic re-read the physical terminal width via shutil.get_terminal_size() and ignored an explicitly set display.width. This was a regression from the 0.22→0.23 change of the max_columns default from 20 to 0; the max_columns > 0 path already honored the width.

Changes:

  • display.width now defaults to None, 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).
  • Both the string-level (_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.
  • The IPython-frontend branch of get_console_size keeps 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 (the display.width is not None check now correctly means "user set an explicit width"). A regression test is added; the only pre-existing tests affected were two in test_format.py, updated accordingly.

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>
@jbrockmendel jbrockmendel added Bug Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataFrame rows printed incorrectly as ... (ellipsis) in v0.23

1 participant