Download scripts/verify_dataset.py from clarkkitchen22/MLB-2025-ChatML-Matchups: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/datasets/clarkkitchen22/MLB-2025-ChatML-Matchups/resolve/main/scripts/verify_dataset.py
- Command line
-
hf download hf://datasets/clarkkitchen22/MLB-2025-ChatML-Matchups/scripts/verify_dataset.py
-
curl -L -o verify_dataset.py https://huggingface.co/datasets/clarkkitchen22/MLB-2025-ChatML-Matchups/resolve/main/scripts/verify_dataset.py
2.58 kB
| #!/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() | |