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

Error: 'winning_pitcher': game['decisions'].get('winner',{}).get('fullName',''), KeyError: 'decisions' #9

Closed
philconow opened this issue Jun 27, 2019 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@philconow
Copy link

philconow commented Jun 27, 2019

I ran the following with version 0.0.8 which was running fine a few weeks ago:

import statsapi

start_date = '2019-03-28'
end_date = '2019-06-25'

game_list_2019 = statsapi.schedule(start_date=start_date, end_date=end_date)

And get back this error:

Traceback (most recent call last):
File "C:/Test.py", line 16, in
game_list_2019 = statsapi.schedule(start_date=start_date, end_date=end_date)
File "C:\Users\Philconow\AppData\Local\Programs\Python\Python37\lib\site-packages\statsapi_init_.py", line 161, in schedule
'winning_pitcher': game['decisions'].get('winner',{}).get('fullName',''),
KeyError: 'decisions'

@philconow philconow changed the title Getting an error Error: 'winning_pitcher': game['decisions'].get('winner',{}).get('fullName',''), KeyError: 'decisions' Jun 27, 2019
@toddrob99
Copy link
Owner

Thank you for the report.

This happened because the decisions field is missing in the MLB data for a game. I thought MLB included the decisions field for all completed games, but perhaps there was a suspended game or something else out of the ordinary for which they leave that field out. I’ll take a closer look later today or tomorrow.

The fix is easy regardless of why the data is not included. I just have to change game[‘decisions’] to game.get(‘decisions’,{}) to account for the field missing sometimes.

@philconow
Copy link
Author

Thank you!

@toddrob99
Copy link
Owner

It's due to gamePk 565060 from 6/13 not having the decisions data included, but I don't see anything special about that game. It completed after 8.5 innings, the status is FInal, and the Red Sox beat the Rangers 7-6. MLB Gameday shows W/L/S in the pitching box score, but it is also missing a couple of names for the Red Sox (no name on the row after Brewer, and no name with the save credited). I'll add protection against missing decision data, but I don't know why it's missing.

@toddrob99 toddrob99 self-assigned this Jun 27, 2019
@toddrob99 toddrob99 added the bug Something isn't working label Jun 27, 2019
@toddrob99
Copy link
Owner

Fixed in v0.0.9, update with pip install --upgrade mlb-statsapi.

Thank you for the bug report!

@skellet0r skellet0r mentioned this issue Oct 5, 2019
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