From 1d96223c78cdc81ade30cb90955f5d29958ff94b Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 20 Mar 2026 23:03:43 -0500 Subject: [PATCH] fix: use player_id instead of key_bbref in create_pit_position() (#7) Closes #7 The fallback branch of create_pit_position() used `int(df_data["key_bbref"])` which always raises ValueError for string IDs like 'verlaju01'. The exception was silently swallowed, causing pitchers without defensive stats to receive no position record at all. Fix: use `int(float(df_data["player_id"]))` to match the pattern used in create_pitching_card() on the same file. Co-Authored-By: Claude Sonnet 4.6 --- pitchers/creation.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pitchers/creation.py b/pitchers/creation.py index 064627d..09f38ad 100644 --- a/pitchers/creation.py +++ b/pitchers/creation.py @@ -196,8 +196,8 @@ async def create_new_players( { "p_name": f"{f_name} {l_name}", "cost": NEW_PLAYER_COST, - "image": f'{card_base_url}/{df_data["player_id"]}/' - f'pitchingcard{urllib.parse.quote("?d=")}{release_dir}', + "image": f"{card_base_url}/{df_data['player_id']}/" + f"pitchingcard{urllib.parse.quote('?d=')}{release_dir}", "mlbclub": CLUB_LIST[df_data["Tm_vL"]], "franchise": FRANCHISE_LIST[df_data["Tm_vL"]], "cardset_id": cardset["id"], @@ -268,7 +268,7 @@ async def calculate_pitching_cards( def create_pitching_card(df_data): logger.info( - f'Creating pitching card for {df_data["name_first"]} {df_data["name_last"]} / fg ID: {df_data["key_fangraphs"]}' + f"Creating pitching card for {df_data['name_first']} {df_data['name_last']} / fg ID: {df_data['key_fangraphs']}" ) pow_data = cde.pow_ratings( float(df_data["Inn_def"]), df_data["GS"], df_data["G"] @@ -298,11 +298,11 @@ async def calculate_pitching_cards( int(df_data["GF"]), int(df_data["SV"]), int(df_data["G"]) ), "hand": df_data["pitch_hand"], - "batting": f'#1W{df_data["pitch_hand"]}-C', + "batting": f"#1W{df_data['pitch_hand']}-C", } ) except Exception as e: - logger.error(f'Skipping fg ID {df_data["key_fangraphs"]} due to: {e}') + logger.error(f"Skipping fg ID {df_data['key_fangraphs']} due to: {e}") print("Calculating pitching cards...") pitching_stats.apply(create_pitching_card, axis=1) @@ -333,7 +333,7 @@ async def create_position( def create_pit_position(df_data): if df_data["key_bbref"] in df_p.index: - logger.debug(f'Running P stats for {df_data["p_name"]}') + logger.debug(f"Running P stats for {df_data['p_name']}") pit_positions.append( { "player_id": int(df_data["player_id"]), @@ -355,7 +355,7 @@ async def create_position( try: pit_positions.append( { - "player_id": int(df_data["key_bbref"]), + "player_id": int(float(df_data["player_id"])), "position": "P", "innings": 1, "range": 5, @@ -364,7 +364,7 @@ async def create_position( ) except Exception: logger.error( - f'Could not create pitcher position for {df_data["key_bbref"]}' + f"Could not create pitcher position for {df_data['key_bbref']}" ) print("Calculating pitcher fielding lines now...") @@ -386,7 +386,7 @@ async def calculate_pitcher_ratings(pitching_stats: pd.DataFrame, post_pitchers: pitching_ratings.extend(cpi.get_pitcher_ratings(df_data)) except Exception: logger.error( - f'Could not create a pitching card for {df_data["key_fangraphs"]}' + f"Could not create a pitching card for {df_data['key_fangraphs']}" ) print("Calculating card ratings...") @@ -525,8 +525,8 @@ async def post_player_updates( [ ( "image", - f'{card_base_url}/{df_data["player_id"]}/pitchingcard' - f'{urllib.parse.quote("?d=")}{release_dir}', + f"{card_base_url}/{df_data['player_id']}/pitchingcard" + f"{urllib.parse.quote('?d=')}{release_dir}", ) ] )