Skip to content

Commit

Permalink
fix(fbref): Handle games with missing events
Browse files Browse the repository at this point in the history
Fixes #547
  • Loading branch information
probberechts committed May 9, 2024
1 parent dbeaea3 commit cac6171
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion soccerdata/fbref.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,12 @@ def read_events(
"event_type": event_type,
}
)
df_match_events = pd.DataFrame(match_events).sort_values(by="minute")
df_match_events = pd.DataFrame(match_events)
df_match_events["game"] = game["game"]
df_match_events["league"] = game["league"]
df_match_events["season"] = game["season"]
if len(df_match_events) > 0:
df_match_events.sort_values(by="minute", inplace=True)
events.append(df_match_events)

if len(events) == 0:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_FBref.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def test_read_events_yellow_for_manager() -> None:
assert "Pepe Bordalás" in yellow_cards["player1"].tolist()


def test_missing_events() -> None:
fbref = sd.FBref("FRA-Ligue 1", "19-20")
events = fbref.read_events(match_id="1d845950")
assert len(events) == 0


def test_read_shot_events(fbref_ligue1: FBref) -> None:
assert isinstance(fbref_ligue1.read_shot_events(match_id="796787da"), pd.DataFrame)

Expand Down

0 comments on commit cac6171

Please sign in to comment.