Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WhoScored] Issue in scrapping if game has no goal #132

Closed
BenSarfatiDS opened this issue Jan 2, 2023 · 0 comments
Closed

[WhoScored] Issue in scrapping if game has no goal #132

BenSarfatiDS opened this issue Jan 2, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@BenSarfatiDS
Copy link

Hello everyone,

If you try to scrap a game from WhoScored using the package, with a 0-0 score, a KeyError occurs.
Within the file whoscored.py at line 676, the process try to access the feature 'is_goal', which seems to not exist if the score at the end of the game is 0-0.

Example of game where this issue happen : https://www.whoscored.com/Matches/1640849/Live/England-Premier-League-2022-2023-Newcastle-Leeds

Python code :

import soccerdata as sd
ws = sd.WhoScored(leagues="ENG-Premier League", seasons="22-23")
events = ws.read_events(match_id=1640849)

Error :

KeyError:
['is_goal'] not in index

A solution could be to check if all the necessary features are indeed part of the dataframe, and if not, add it with np.nan values.
The python code could be as follow, before the line 676 :

Python code :

cols = ['event_id', 'expanded_minute', 'is_touch', 'minute', 'outcome_type',
'period', 'qualifiers', 'satisfied_events_types', 'second', 'team_id',
'type', 'x', 'y', 'end_x', 'end_y', 'player_id', 'blocked_x',
'blocked_y', 'goal_mouth_y', 'goal_mouth_z', 'is_shot',
'related_event_id', 'related_player_id', 'is_goal', 'card_type', '$idx',
'$len', 'field', 'minute_info', 'satisfiers', 'text', 'game_id',
'player', 'team']

for col in cols:
if col not in df.columns:
df[col] = np.nan

PS: It exists a similar issue with feature 'card_type' if no card were given during the game.

Thanks,
Ben

@probberechts probberechts added the bug Something isn't working label Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants