Spaces:
Running
Running
| 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() | |