From 7fd482e6de3eb3aebc949c8049580b796accafc7 Mon Sep 17 00:00:00 2001 From: yasumorishima Date: Wed, 4 Feb 2026 20:36:11 +0900 Subject: [PATCH 1/2] Add input validation to team_fielding_bref (#462) - Add team.upper() to handle case-insensitive team abbreviations - Add end_season < start_season validation with clear error message --- pybaseball/team_fielding.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pybaseball/team_fielding.py b/pybaseball/team_fielding.py index 7546e5e2..45fa7b4a 100644 --- a/pybaseball/team_fielding.py +++ b/pybaseball/team_fielding.py @@ -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 = [] From ca24a8052f934f87ab4b66613b490aa7f59a02e3 Mon Sep 17 00:00:00 2001 From: yasumorishima Date: Mon, 15 Jun 2026 13:16:43 +0900 Subject: [PATCH 2/2] test: add regression test for team_fielding_bref invalid season range (#462) --- tests/pybaseball/test_team_fielding.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/pybaseball/test_team_fielding.py b/tests/pybaseball/test_team_fielding.py index 2ab17fa7..047813e5 100644 --- a/tests/pybaseball/test_team_fielding.py +++ b/tests/pybaseball/test_team_fielding.py @@ -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)