Michael Rabinovich commited on
Commit
00d091d
·
1 Parent(s): a58058c

leaderboard: handle null score fields on pending / failed rows

Browse files

The pending row landed by chunk 3 carries null validity_rate +
aggregate_score (correct per the schema). pandas coerces JSON null
to NaN on column construction, and _fmt_pct's `if x is None`
gate didn't catch NaN; int(NaN) then raised ValueError inside
.map(), bringing down load_leaderboard and rendering the
leaderboard tab as a generic "Error".

Fix:
- _fmt_pct: gate on pd.isna(x) (catches both None and NaN),
return "" for null.
- _fmt_score: matching formatter for aggregate_score (was
previously rendered as the raw float; with nulls in the
mix it'd show as "NaN" cells). Returns "" for null,
"%.4f" otherwise.

Pending and failed rows now render with blank cells in both
score columns; the row-level status column carries the meaning.

Files changed (1) hide show
  1. leaderboard.py +16 -2
leaderboard.py CHANGED
@@ -66,13 +66,25 @@ def _load_rows_from_local() -> list[dict]:
66
 
67
 
68
  def _fmt_pct(x: float | None) -> str:
69
- """Render a 0-1 fraction as 'NN%' (or 'NN.N%' for non-whole values)."""
70
- if x is None:
 
 
 
 
 
71
  return ""
72
  pct = float(x) * 100
73
  return f"{pct:.0f}%" if pct == int(pct) else f"{pct:.1f}%"
74
 
75
 
 
 
 
 
 
 
 
76
  def load_leaderboard() -> pd.DataFrame:
77
  rows = _load_rows_from_hub()
78
  if rows is None:
@@ -96,4 +108,6 @@ def load_leaderboard() -> pd.DataFrame:
96
  )
97
  if "validity_rate" in df.columns:
98
  df["validity_rate"] = df["validity_rate"].map(_fmt_pct)
 
 
99
  return df
 
66
 
67
 
68
  def _fmt_pct(x: float | None) -> str:
69
+ """Render a 0-1 fraction as 'NN%' (or 'NN.N%' for non-whole values).
70
+
71
+ ``pandas`` coerces JSON ``null`` to ``NaN`` on column construction,
72
+ so ``pd.isna`` is the safe gate (catches both ``None`` and ``NaN``).
73
+ Returns ``""`` so pending / failed rows render with blank cells.
74
+ """
75
+ if pd.isna(x):
76
  return ""
77
  pct = float(x) * 100
78
  return f"{pct:.0f}%" if pct == int(pct) else f"{pct:.1f}%"
79
 
80
 
81
+ def _fmt_score(x: float | None) -> str:
82
+ """Render an aggregate CAD score as a 4-decimal float, blank on null."""
83
+ if pd.isna(x):
84
+ return ""
85
+ return f"{float(x):.4f}"
86
+
87
+
88
  def load_leaderboard() -> pd.DataFrame:
89
  rows = _load_rows_from_hub()
90
  if rows is None:
 
108
  )
109
  if "validity_rate" in df.columns:
110
  df["validity_rate"] = df["validity_rate"].map(_fmt_pct)
111
+ if "aggregate_score" in df.columns:
112
+ df["aggregate_score"] = df["aggregate_score"].map(_fmt_score)
113
  return df