From 5437a379ed3746dd2f41d8d4e47bb4f8511cec92 Mon Sep 17 00:00:00 2001 From: ANIS <119749586+assinscreedFC@users.noreply.github.com> Date: Sat, 6 Jun 2026 00:38:11 +0200 Subject: [PATCH] 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 --- tabulate/__init__.py | 2 +- test/test_regression.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 12a2950..c13366d 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -1652,7 +1652,7 @@ def _wrap_text_to_colwidths( else ( str(cell) if cell == "" or _isnumber(cell) - else str(_type(cell, numparse)(cell)) + else str(_type(cell, numparse=numparse)(cell)) ) ) wrapped = [ diff --git a/test/test_regression.py b/test/test_regression.py index 9555676..dfc7a21 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -531,6 +531,16 @@ def test_exception_on_empty_data_with_maxcolwidths(): assert_equal(result, "") +def test_disable_numparse_honored_with_maxcolwidths(): + "Regression: disable_numparse honored on the wrap path (github issue #428)" + # A number-ish but unparseable cell ('80,443') must not be parsed when + # disable_numparse=True, even when maxcolwidths triggers the wrap path. + table = [["ports", "str", "comma-separated port list", "80,443"]] + headers = ["name", "type", "desc", "default"] + result = tabulate(table, headers, tablefmt="grid", disable_numparse=True, maxcolwidths=40) + assert "80,443" in result + + def test_numpy_int64_as_integer(): "Regression: format numpy.int64 as integer (github issue #18)" try: