Coverage for scripts/v664_table_smoke.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""Builds every trial's table of a round on its cell and reports coverage: names per rebalance and the first and last date with any value (V6.6.4). 

2 

3This scores nothing and reads no return: it checks that a pre-registered trial can be built from the cell's data, so a defect shows before the rule file is hashed and not after. It runs on a 

4free cell only. 

5 

6 python scripts/v664_table_smoke.py ml/evaluation/v664/round4c_draft.json 

7""" 

8 

9from __future__ import annotations 

10 

11import json 

12import sys 

13from pathlib import Path 

14 

15ROOT = Path(__file__).resolve().parents[1] 

16sys.path.insert(0, str(ROOT)) 

17 

18import pandas as pd # noqa: E402 

19 

20from evaluation.research_cells import FREE_CELLS # noqa: E402 

21from evaluation.research_round import RoundSpec, live_rows, trial_table # noqa: E402 

22from evaluation.research_round import _load_selection_cell as load_cell # noqa: E402 

23from portfolio.wide_signals import live_names_per_rebalance # noqa: E402 

24 

25 

26def smoke(spec: RoundSpec, score_dir: Path, *, emit=print) -> dict: 

27 if spec.cell not in FREE_CELLS: 

28 raise PermissionError("the smoke test opens free cells only") 

29 cell = load_cell(spec, ROOT) 

30 built: dict[str, pd.DataFrame] = {} 

31 report: dict[str, dict] = {} 

32 for trial, entry in spec.trials.items(): 

33 table = trial_table(spec, trial, cell, built, score_dir=score_dir) 

34 if table is None: 

35 report[trial] = {"built": False} 

36 emit(f"{trial}: not built (an input or a part is missing)") 

37 continue 

38 built[trial] = table 

39 start = str(entry.get("start") or cell.cell.start) 

40 live = live_names_per_rebalance(live_rows(table.loc[table.index >= start], entry), int(entry.get("rebalance_every", 20))) 

41 any_value = table.notna().any(axis=1) 

42 report[trial] = { 

43 "built": True, "median_live_names": live["median"], "min_live_names": live["minimum"], "first": str(any_value.idxmax()) if any_value.any() else None, 

44 "last": str(any_value[::-1].idxmax()) if any_value.any() else None, 

45 } 

46 emit(f"{trial}: live names median {live['median']:.0f} min {live['minimum']:.0f}, values from {report[trial]['first']} to {report[trial]['last']}") 

47 return report 

48 

49 

50def main() -> int: 

51 from evaluation.research_round import RoundSpec as Spec 

52 

53 draft = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) 

54 spec = Spec( 

55 name=draft["name"], cell=draft["cell"], side=draft["side"], bar=draft["bar"], rule=draft["rule"], trials=draft["trials"], out_dir=ROOT / draft["out_dir"], ledger=ROOT / draft["ledger"], 

56 track=draft["track"], min_live_names=int(draft["min_live_names"]), min_ic_names=int(draft["min_ic_names"]), no_ic_clause=tuple(draft.get("no_ic_clause") or ()), raw=draft, 

57 ) 

58 smoke(spec, spec.out_dir / "scores") 

59 return 0 

60 

61 

62if __name__ == "__main__": 

63 raise SystemExit(main())