Skip to content
Merged
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
2 changes: 1 addition & 1 deletion tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ def _format(val, valtype, floatfmt, intfmt, missingval="", has_invisible=True):
elif valtype is bytes:
try:
return str(val, "ascii")
except TypeError:
except (TypeError, UnicodeDecodeError):
return str(val)
elif valtype is float:
is_a_colored_number = has_invisible and isinstance(val, (str, bytes))
Expand Down
10 changes: 10 additions & 0 deletions test/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,13 @@ def test_py37orlater_list_of_dataclasses_headers():
assert_equal(expected, result)
except ImportError:
skip("test_py37orlater_list_of_dataclasses_headers is skipped")


def test_list_bytes():
"Input: a list of bytes. (issue #192)"
lb = [["你好".encode("utf-8")], ["你好"]]
expected = "\n".join(
["bytes", "---------------------------", r"b'\xe4\xbd\xa0\xe5\xa5\xbd'", "你好"]
)
result = tabulate(lb, headers=["bytes"])
assert_equal(expected, result)