toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
547 stars 99 forks source link

boxscore_data fails with specific gamepk 448650 #37

Closed paulinglucas closed 4 years ago

paulinglucas commented 4 years ago

I was iterating through games of the 2016 season and saw that when I tried to call boxscore_data() on gamepk 448650 it failed with "KeyError: inningsPitched." Not sure what's causing the issue but wanted to bring it to someone's attention.

Outside of this the library has been a lot of fun to mess around with season statistics :) keep up the great work!

toddrob99 commented 4 years ago

Thanks for posting. I haven’t looked at the data yet, but that error means one of the pitchers listed in the API response is missing the inningsPitched field. That field should be there for any pitcher who pitched in the game, so I’ll have to dig into the data to see why it is missing.

marczigabor commented 4 years ago

Hi,

I think my finding is related to this issue. The boxscore_data call throws error for multiple gamePks.

For example: gamePk: 5632

Error message: if boxData[side]["players"]["ID" + pitcherId]["stats"]["pitching"].get( 685 "note" 686 ) KeyError: 'ID118421'

As I checked the original dataset is wrong. http://statsapi.mlb.com/api/v1/game/5632/boxscore

The player with the Id 118421 appears in the "home" and "away" "pitchers" section as well.

Other failed gamePks with the similar error: 5024, 4975

Thanks for the library. Great work. :)

toddrob99 commented 4 years ago

@paulinglucas, in the case of game 448650, the error happens because Ubaldo Jimenez (personId 434622) is listed as a pitcher, but there is no pitching data included for him. The game ended early due to rain. The last play in the MLB data shows a field out followed by a pitching change (Jimenez coming in), but the inning was over at that point and Jimenez never threw a pitch. I don't know why the data reflects a pitching change after the third out was recorded, but that bad data is the problem here. Here is the game summary on ESPN which does not show the pitching change in the play-by-play.

I will update the boxscore_data method to ignore any pitchers that don't have pitching data. I just pushed a fix to the develop branch, and I will include it in the next release.

toddrob99 commented 4 years ago

@marczigabor, I also added a fix to handle pitchers listed under the wrong team. It will be included in the next release, and I'm pushing to the develop branch now.