Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pybaseball/team_fielding.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def team_fielding_bref(team: str, start_season: int, end_season: Optional[int]=N
)
if end_season is None:
end_season = start_season
if end_season < start_season:
raise ValueError(
"end_season must be greater than or equal to start_season."
)

team = team.upper()
url = "https://www.baseball-reference.com/teams/{}".format(team)

raw_data = []
Expand Down
9 changes: 9 additions & 0 deletions tests/pybaseball/test_team_fielding.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ def test_team_fielding(response_get_monkeypatch: Callable, sample_html: str, sam
team_fielding_result = team_fielding(season).reset_index(drop=True)

pd.testing.assert_frame_equal(team_fielding_result, sample_processed_result, check_dtype=False)


def test_team_fielding_bref_invalid_season_range() -> None:
# Regression test for #462: an end_season earlier than start_season should
# raise a clear ValueError before any network request is made.
from pybaseball.team_fielding import team_fielding_bref

with pytest.raises(ValueError):
team_fielding_bref('NYY', 2019, 2018)