Skip to content

Commit d477b09

Browse files
author
y-p
committed
BUG: rework get_console_size to handle cases properly
1 parent f48a954 commit d477b09

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

pandas/core/format.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -1675,16 +1675,37 @@ def detect_console_encoding():
16751675

16761676

16771677
def get_console_size():
1678-
"""Return console size as tuple = (width, height)."""
1678+
"""Return console size as tuple = (width, height).
1679+
1680+
May return (None,None) in some cases.
1681+
"""
16791682
display_width = get_option('display.width')
16801683
display_height = get_option('display.height')
16811684

1682-
if com.in_interactive_session() and not com.in_ipnb_frontend():
1683-
# pure terminal
1684-
terminal_width, terminal_height = get_terminal_size()
1685+
# Consider
1686+
# interactive shell terminal, can detect term size
1687+
# interactive non-shell terminal (ipnb/ipqtconsole), cannot detect term size
1688+
# non-interactive script, should disregard term size
1689+
1690+
# in addition
1691+
# width,height have default values, but setting to 'None' signals
1692+
# should use Auto-Detection, But only in interactive shell-terminal.
1693+
# Simple. yeah.
1694+
1695+
if com.in_interactive_session():
1696+
if com.in_ipnb_frontend():
1697+
# sane defaults for interactive non-shell terminal
1698+
# match default for width,height in config_init
1699+
terminal_width, terminal_height = 100, 60
1700+
else:
1701+
# pure terminal
1702+
terminal_width, terminal_height = get_terminal_size()
16851703
else:
1686-
terminal_width, terminal_height = 100, 60
1704+
terminal_width, terminal_height = None,None
16871705

1706+
# Note if the User sets width/Height to None (auto-detection)
1707+
# and we're in a script (non-inter), this will return (None,None)
1708+
# caller needs to deal.
16881709
return (display_width or terminal_width, display_height or terminal_height)
16891710

16901711

0 commit comments

Comments
 (0)