From 40d22ae61e99b489d6f81a1ad6e48e4e00662428 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 3 Jul 2024 09:54:55 -0500 Subject: [PATCH] Fix incorrect player match --- creation_helpers.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/creation_helpers.py b/creation_helpers.py index 70b6be6..69e8b42 100644 --- a/creation_helpers.py +++ b/creation_helpers.py @@ -999,13 +999,19 @@ def get_all_pybaseball_ids(player_id: list, key_type: str, is_custom: bool = Fal elif full_name is not None: names = full_name.split(' ') q = pb.playerid_lookup(last=names[-1], first=' '.join(names[:-1]), fuzzy=True) - if len(q.values) > 0: - return_val = q.loc[0] - return_val['key_fangraphs'] = player_id[0] - else: + if len(q.values) == 0: logging.error(f'get_all_pybaseball_ids - Could not find id {player_id} / {key_type} or ' f'{full_name} / full name in pybaseball') - return_val = None + return None + elif len(q.values) > 1: + # q = q.drop(q[q['mlb_played_last'].isnull()]) + # q.astype({'mlb_played_last': 'int32'}) + # q = q.dropna() + q = q.drop(q[q['mlb_played_last'] == ''].index) + q = q.sort_values(by=['mlb_played_last'], ascending=False) + + return_val = q.loc[0] + return_val['key_fangraphs'] = player_id[0] else: logging.error(f'get_all_pybaseball_ids - Could not find id {player_id} / {key_type} in pybaseball') return_val = None