Browse Source

fix pretty table unicode displaly

tags/v0.4.10
unknown 5 years ago
parent
commit
9c5b778df0
1 changed files with 16 additions and 4 deletions
  1. +16
    -4
      fastNLP/core/utils.py

+ 16
- 4
fastNLP/core/utils.py View File

@@ -777,6 +777,7 @@ def pretty_table_printer(dataset_or_ins) -> PrettyTable:
except OSError:
column = 144
row = 11

if type(dataset_or_ins).__name__ == "DataSet":
x.field_names = list(dataset_or_ins.field_arrays.keys())
c_size = len(x.field_names)
@@ -793,6 +794,8 @@ def pretty_table_printer(dataset_or_ins) -> PrettyTable:

else:
raise Exception("only accept DataSet and Instance")
x.align = "l"

return x


@@ -804,11 +807,20 @@ def sub_column(string: str, c: int, c_size: int, title: str) -> str:
:param title: 列名
:return: 对一个过长的列进行截断的结果
"""
avg = max(int(c / c_size), len(title))
avg = max(int(c / c_size / 2), len(title))
string = str(string)
if len(string) > avg:
string = string[:(avg - 3)] + "..."
return string
res = ""
counter = 0
for char in string:
if ord(char) > 255:
counter += 2
else:
counter += 1
res += char
if counter > avg:
res = res + "..."
break
return res


def _check_fp16():


Loading…
Cancel
Save