Skip to content

Commit

Permalink
fix(fbref):Handle yellow card events for non-players (#566)
Browse files Browse the repository at this point in the history
Fixes #544

Co-authored-by: Pieter Robberechts <[email protected]>
  • Loading branch information
nachouve and probberechts authored May 9, 2024
1 parent 55d80ca commit dbeaea3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion soccerdata/fbref.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def read_events(
for e in html_events:
minute = e.xpath("./div[1]")[0].text.replace("&rsquor;", "").strip()
score = e.xpath("./div[1]/small/span")[0].text
player1 = e.xpath("./div[2]/div[2]/div/a")[0].text
player1 = e.xpath("./div[2]/div[2]/div")[0].text_content().strip()
if e.xpath("./div[2]/div[2]/small/a"):
player2 = e.xpath("./div[2]/div[2]/small/a")[0].text
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_FBref.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def test_read_events(fbref_ligue1: FBref) -> None:
assert isinstance(fbref_ligue1.read_events(match_id="796787da"), pd.DataFrame)


def test_read_events_yellow_for_manager() -> None:
"""When a yellow card given to the manager, there is no <a> tag."""
fbref_laliga = sd.FBref("ESP-La Liga", "23-24")
events = fbref_laliga.read_events(match_id="e8867e6b")
yellow_cards = events[events["event_type"] == "yellow_card"]
assert "Pepe Bordalás" in yellow_cards["player1"].tolist()


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 dbeaea3

Please sign in to comment.