Spaces:
Running
Running
File size: 1,453 Bytes
7b3d14f | 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 | from __future__ import annotations
import os
import sys
import unittest
import pandas as pd
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from data.statcast import normalize_statcast
class TestStatcastNormalization(unittest.TestCase):
def test_normalize_statcast_preserves_matchup_lookup_fields(self) -> None:
df = pd.DataFrame(
[
{
"player_name": "Slugger Sam",
"batter": 123,
"pitcher": 456,
"p_throws": "L",
"stand": "R",
"inning_topbot": "Top",
"away_team": "Away Team",
"home_team": "Home Team",
"game_date": "2026-03-20",
}
]
)
normalized = normalize_statcast(df)
self.assertIn("batter", normalized.columns)
self.assertIn("pitcher", normalized.columns)
self.assertIn("inning_topbot", normalized.columns)
self.assertIn("p_throws", normalized.columns)
self.assertIn("pitcher_hand", normalized.columns)
self.assertEqual(int(normalized.iloc[0]["batter"]), 123)
self.assertEqual(int(normalized.iloc[0]["pitcher"]), 456)
self.assertEqual(str(normalized.iloc[0]["p_throws"]), "L")
self.assertEqual(str(normalized.iloc[0]["pitcher_hand"]), "L")
if __name__ == "__main__":
unittest.main()
|