`Table(min_width=...)` raises `AssertionError: Sum of ratios must be > 0` on a very narrow console
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The failure is in Table._calculate_column_widths in rich/table.py, where ratio_distribute is called with column widths that all sum to 0 when min_width exceeds the available space. Start by reproducing with the snippet in the issue at widths 1 and 2, then check whether padding should be skipped when no column has width. Done means the table renders at those widths with min_width set, and a test covers the narrow Panel case as well.
Written by the indexing model from the issue text.
Description
Hi! I hit this while writing generated tests against Rich. Printing a table that has a min_width raises AssertionError when the console is so narrow that the columns get no width at all:
from rich.console import Console
from rich.table import Table
for width in (1, 2, 3, 10):
console = Console(width=width, color_system=None)
try:
console.print(Table("a", min_width=5))
print(f"width {width}: rendered")
except Exception as error:
print(f"width {width}: {type(error).__name__}: {error}")
Output on Rich 15.0.0 and on main (3a109cc), with the tables themselves left out:
width 1: AssertionError: Sum of ratios must be > 0
width 2: AssertionError: Sum of ratios must be > 0
width 3: rendered
width 10: rendered
Without min_width, the same table renders at widths 1 and 2 (cut down to its borders), and so does expand=True.
In Table._calculate_column_widths, every column width is 0 at these sizes, and the table is still narrower than min_width, so it pads the columns with ratio_distribute(_max_width - table_width, widths). The ratios are the widths, which sum to 0, and ratio_distribute asserts they don't.
It can also happen inside a narrow container: console.print(Panel(Table("a", min_width=5), width=5)) on a 40-column console raises the same error. I'd expect it to render like the table without min_width does. I have a small fix that skips the padding when no column has any width, and I'm happy to open a PR.
Python 3.13, macOS.
- Dominant language
- Python
- Stars
- 57.8k
- Forks
- 2.6k
- Avg merge
- 20m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/rich
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Textualize/rich#4269 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Textualize/rich#4268 ·
-
Needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Textualize/rich#4267 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Textualize/rich#4265 ·
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day