File size: 2,580 Bytes
af467a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import json
from pathlib import Path

import pyarrow.parquet as pq

from build_dataset import MlbApiClient, load_schedule


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description="Verify the generated MLB ChatML parquet dataset.")
    parser.add_argument(
        "--parquet",
        type=Path,
        default=Path("data/processed/mlb_2025_chatml_matchups.parquet"),
    )
    parser.add_argument("--cache-dir", type=Path, default=Path(".cache/mlb_api"))
    parser.add_argument("--max-rps", type=float, default=4.0)
    return parser.parse_args()


def main() -> None:
    args = parse_args()
    if not args.parquet.exists():
        raise SystemExit(f"missing parquet file: {args.parquet}")

    table = pq.read_table(args.parquet)
    rows = table.to_pylist()
    client = MlbApiClient(cache_dir=args.cache_dir, max_rps=args.max_rps)
    games = load_schedule(client, "2025-03-01", "2025-11-30")
    expected_rows = len(games) * 2

    row_ids = [row["row_id"] for row in rows]
    game_pks = {row["game_pk"] for row in rows}
    team_ids = {row["team_id"] for row in rows}
    bad_messages = [
        row["row_id"]
        for row in rows
        if [message["role"] for message in row["messages"]] != ["system", "user", "assistant"]
    ]
    missing_pitching = [
        row["row_id"]
        for row in rows
        if not json.loads(row["team_game_pitching_json"])
        or not json.loads(row["team_season_pitching_json"])
        or not json.loads(row["opponent_game_pitching_json"])
    ]

    checks = {
        "rows_match_schedule_x2": len(rows) == expected_rows,
        "unique_row_ids": len(row_ids) == len(set(row_ids)),
        "all_games_present": len(game_pks) == len(games),
        "all_30_teams_present": len(team_ids) == 30,
        "chatml_roles_valid": not bad_messages,
        "pitching_fields_present": not missing_pitching,
    }
    print(
        json.dumps(
            {
                "parquet": str(args.parquet),
                "rows": len(rows),
                "expected_rows": expected_rows,
                "games": len(games),
                "teams": len(team_ids),
                "checks": checks,
                "api_metrics": client.metrics.__dict__,
            },
            indent=2,
            sort_keys=True,
        )
    )
    failed = [name for name, passed in checks.items() if not passed]
    if failed:
        raise SystemExit(f"verification failed: {failed}")


if __name__ == "__main__":
    main()