Skip to content

Commit

Permalink
fix teamid lookup warning stuff (#433)
Browse files Browse the repository at this point in the history
* Rewrite the retrosheet fix with if/elif to avoid requiring 3.10

* Fix team ID lookup stuff etc
  • Loading branch information
schorrm authored Jun 16, 2024
1 parent b7ecf3c commit ae2da3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
16 changes: 9 additions & 7 deletions pybaseball/retrosheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ def events(season, type='regular', export_dir='.'):
if not os.path.exists(export_dir):
os.mkdir(export_dir)

match type:
case 'regular':
file_extension = ('.EVA','.EVN')
case 'post':
file_extension = ('CS.EVE','D1.EVE','D2.EVE','W1.EVE','W2.EVE','WS.EVE')
case 'asg':
file_extension = ('AS.EVE')
if type == 'regular':
file_extension = ('.EVA','.EVN')
elif type == 'post':
file_extension = ('CS.EVE','D1.EVE','D2.EVE','W1.EVE','W2.EVE','WS.EVE')
elif type == 'asg':
file_extension = ('AS.EVE')
else:
raise RuntimeError(f"Illegal type argument {type}, "
"the valid types are: 'regular', 'post', and 'asg'.")

try:
g = Github(GH_TOKEN)
Expand Down
2 changes: 1 addition & 1 deletion pybaseball/teamid_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _front_loaded_ratio(str_1: str, str_2: str) -> float:
'''

if len(str_1) != 3 or len(str_2) != 3:
logger.warn(
logger.warning(
"This ratio is intended for 3 length string comparison (such as a lahman teamID, franchID, or teamIDBR."
"Returning 0 for non-compliant string(s)."
)
Expand Down
3 changes: 2 additions & 1 deletion tests/pybaseball/test_teamid_lookup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pandas as pd
import pytest
import warnings

from pybaseball.teamid_lookup import _front_loaded_ratio, _get_close_team_matches, team_ids

Expand Down Expand Up @@ -66,7 +67,7 @@ def test_front_loaded_ratio(team1: str, team2: str, expected_ratio: int) -> None
if len(team1) == 3 and len(team2) == 3:
assert round(_front_loaded_ratio(team1, team2), 2) == expected_ratio
else:
with pytest.warns(None):
with warnings.catch_warnings(record=True):
assert _front_loaded_ratio(team1, team2) == 0

def test_get_close_team_matches() -> None:
Expand Down

0 comments on commit ae2da3a

Please sign in to comment.