Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,13 @@ def _wrap_text_to_colwidths(
if cell is None
else (
str(cell)
if cell == "" or _isnumber(cell)
if cell == ""
or _isnumber(cell)
or (isinstance(cell, str) and _ansi_codes.search(cell))
or (
isinstance(cell, bytes)
and _ansi_codes_bytes.search(cell)
)
else str(_type(cell, numparse)(cell))
)
)
Expand Down
9 changes: 9 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,15 @@ def test_exception_on_empty_data_with_maxcolwidths():
assert_equal(result, "")


def test_colored_number_with_maxcolwidths():
"Regression: ANSI-colored numeric strings crash when wrapped by maxcolwidths (github issue #359)"
colored_three = "\033[31m3\033[0m"
result = tabulate([[colored_three]], maxcolwidths=10)
assert "3" in result
assert "\033[31m" in result
assert "\033[0m" in result


def test_numpy_int64_as_integer():
"Regression: format numpy.int64 as integer (github issue #18)"
try:
Expand Down