Skip to content

Commit

Permalink
Fix logic for determining if team is Home or Away for team game logs (#…
Browse files Browse the repository at this point in the history
…237)

* Fix buglet

* Added tests
  • Loading branch information
jzuhusky committed Sep 13, 2021
1 parent a28f141 commit 921f8a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pybaseball/team_game_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def postprocess(data):
"Pitchers Used (Rest-GameScore-Dec)": "PitchersUsed"
}
data.rename(repl_dict, axis=1, inplace=True)
data["Home"] = ~data["Home"].isnull() # '@' if away, empty if home
data["Home"] = data["Home"].isnull() # '@' if away, empty if home
data = data[data["Game"].str.match(r"\d+")] # drop empty month rows
data = data.apply(pd.to_numeric, errors="ignore")
data["Game"] = data["Game"].astype(int)
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/pybaseball/test_team_game_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pybaseball


def test_nyy_game_logs_regression1() -> None:
"""Regression test for NYY 2021 example"""
df = pybaseball.team_game_logs(2021, "NYY", "pitching")

# NYY home against TOR 9/9/2021
assert df.loc[139]["Home"]

# subway series 9/11/2021, NYY playing Mets @ Citi (NYY is Away)
assert not df.loc[141]["Home"]

0 comments on commit 921f8a0

Please sign in to comment.