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_output.py b/test/test_output.py index ea3da87..41d99b8 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -3292,6 +3292,18 @@ def test_disable_numparse_true(): assert_equal(expected, result) +def test_disable_numparse_maxcolwidths_keeps_thousands_separator(): + "Wrapping must not parse a disabled numeric column such as 100,120" + result = tabulate( + [["100,120"]], + headers=["x"], + tablefmt="plain", + maxcolwidths=[20], + disable_numparse=True, + ) + assert "100,120" in result + + def test_disable_numparse_list(): "Output: Default table output, but with number parsing selectively disabled" table_headers = ["h1", "h2", "h3"] diff --git a/test/test_selective_wrapped_numparse.py b/test/test_selective_wrapped_numparse.py new file mode 100644 index 0000000..4656dce --- /dev/null +++ b/test/test_selective_wrapped_numparse.py @@ -0,0 +1,17 @@ +from tabulate import tabulate + + +def test_selective_numparse_preserves_wrapped_text_and_numeric_neighbor(): + result = tabulate( + [["100,120", "1.2300"]], + headers=["id", "amount"], + tablefmt="plain", + maxcolwidths=[4, None], + disable_numparse=[0], + ) + + assert [line.split() for line in result.splitlines()] == [ + ["id", "amount"], + ["100,", "1.23"], + ["120"], + ]