Skip to content

Commit 5437a37

Browse files
committed
Honor disable_numparse on the maxcolwidths wrap path
In _wrap_text_to_colwidths, the per-cell numparse flag was passed positionally to _type() as the has_invisible argument: _type(cell, numparse) so _type() always used its default numparse=True. A number-ish but unparseable cell (e.g. '80,443') was then cast to int and crashed with ValueError, but only when maxcolwidths triggered the wrap path -- the non-wrap path honored disable_numparse correctly. Pass numparse as a keyword argument. This restores the fix from #362 (regression of #305 / #428). Fixes #428
1 parent 268615a commit 5437a37

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

tabulate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ def _wrap_text_to_colwidths(
16521652
else (
16531653
str(cell)
16541654
if cell == "" or _isnumber(cell)
1655-
else str(_type(cell, numparse)(cell))
1655+
else str(_type(cell, numparse=numparse)(cell))
16561656
)
16571657
)
16581658
wrapped = [

test/test_regression.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,16 @@ def test_exception_on_empty_data_with_maxcolwidths():
531531
assert_equal(result, "")
532532

533533

534+
def test_disable_numparse_honored_with_maxcolwidths():
535+
"Regression: disable_numparse honored on the wrap path (github issue #428)"
536+
# A number-ish but unparseable cell ('80,443') must not be parsed when
537+
# disable_numparse=True, even when maxcolwidths triggers the wrap path.
538+
table = [["ports", "str", "comma-separated port list", "80,443"]]
539+
headers = ["name", "type", "desc", "default"]
540+
result = tabulate(table, headers, tablefmt="grid", disable_numparse=True, maxcolwidths=40)
541+
assert "80,443" in result
542+
543+
534544
def test_numpy_int64_as_integer():
535545
"Regression: format numpy.int64 as integer (github issue #18)"
536546
try:

0 commit comments

Comments
 (0)