Fix incorrect player match

This commit is contained in:
Cal Corum 2024-07-03 09:54:55 -05:00
parent cd62e3807a
commit 40d22ae61e

View File

@ -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