fix: guard against None rating objects in pitcher sorting functions (#13)

Add None checks for vlval/vrval in get_total_ops inside sort_pitchers()
and sort_starters(). Returns float("inf") when ratings are missing so
pitchers without ratings sort to the end rather than raising AttributeError.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-03 20:03:50 -06:00
parent 761c0a6dab
commit 8d1751c061

View File

@ -600,6 +600,8 @@ def sort_pitchers(pitching_card_query) -> DataFrame | None:
PitchingCardRatings.vs_hand == "R",
)
if vlval is None or vrval is None:
return float("inf")
ops_vl = vlval.obp + vlval.slg
ops_vr = vrval.obp + vrval.slg
# TODO: should this be max??
@ -677,6 +679,8 @@ async def get_team_sp(
PitchingCardRatings.vs_hand == "R",
)
if vlval is None or vrval is None:
return float("inf")
ops_vl = vlval.obp + vlval.slg
ops_vr = vrval.obp + vrval.slg
return (ops_vr + ops_vl + min(ops_vl, ops_vr)) / 3