albertvillanova HF staff commited on
Commit
e3edf6d
1 Parent(s): 19a6010

Fix wrapping to keep non-str data

Browse files
Files changed (1) hide show
  1. src/details.py +9 -1
src/details.py CHANGED
@@ -68,7 +68,15 @@ def display_details(sample_idx, *dfs):
68
  # Pop model_name and add it to the column name
69
  df = pd.concat([row.rename(row.pop("model_name")) for row in rows], axis="columns")
70
  # Wrap long strings to avoid overflow; e.g. URLs in "doc.Websites visited_NEV_2"
71
- df = df.apply(lambda x: x.str.wrap(140) if x.dtype == "object" else x)
 
 
 
 
 
 
 
 
72
  return (
73
  df.style
74
  .format(escape="html", na_rep="")
 
68
  # Pop model_name and add it to the column name
69
  df = pd.concat([row.rename(row.pop("model_name")) for row in rows], axis="columns")
70
  # Wrap long strings to avoid overflow; e.g. URLs in "doc.Websites visited_NEV_2"
71
+ def wrap(row):
72
+ try:
73
+ result = row.str.wrap(140)
74
+ return result if result.notna().all() else row # NaN when data is a list
75
+ except AttributeError: # when data is number
76
+ return row
77
+
78
+ df = df.apply(wrap, axis=1)
79
+ # Style
80
  return (
81
  df.style
82
  .format(escape="html", na_rep="")