MLB-StatsAPI
MLB-StatsAPI copied to clipboard
parentTeamId of player sometimes missing in statsapi.boxscore_data(game_id)
To reproduce for example store this game into a json:
import json
import statsapi
# Get game data for specific game ID
game_id = "778110"
try:
# Get game data
game_data = statsapi.boxscore_data(game_id)
# Write game data to file
output_file = f"{game_id}.json"
with open(output_file, "w") as f:
json.dump(game_data, f, indent=2)
Now check the player Blubaugh:
"ID805123": {
"person": {
"id": 805123,
"fullName": "AJ Blubaugh"
},
"position": {
"abbreviation": "P"
},
"status": {},
"stats": {
"batting": {},
"pitching": {
"note": "(L, 0-1)",
"runs": 7,
"doubles": 0,
"triples": 0,
"homeRuns": 2,
"strikeOuts": 6,
"baseOnBalls": 1,
"hits": 5,
"atBats": 17,
"stolenBases": 0,
"numberOfPitches": 84,
"inningsPitched": "4.0",
"wins": 0,
"losses": 1,
"holds": 0,
"blownSaves": 0,
"earnedRuns": 2,
"pitchesThrown": 84,
"strikes": 51,
"rbi": 7
}
},
"seasonStats": {
"batting": {
"runs": 0,
"doubles": 0,
"triples": 0,
"homeRuns": 0,
"strikeOuts": 0,
"baseOnBalls": 0,
"hits": 0,
"avg": ".000",
"atBats": 0,
"obp": ".000",
"slg": ".000",
"ops": ".000",
"stolenBases": 0,
"rbi": 0,
"leftOnBase": 0
},
"pitching": {
"runs": 7,
"doubles": 0,
"triples": 0,
"homeRuns": 2,
"strikeOuts": 6,
"baseOnBalls": 1,
"hits": 5,
"atBats": 17,
"obp": ".316",
"stolenBases": 0,
"numberOfPitches": 84,
"era": "4.50",
"inningsPitched": "4.0",
"wins": 0,
"losses": 1,
"holds": 0,
"blownSaves": 0,
"earnedRuns": 2,
"pitchesThrown": 84,
"strikes": 51,
"rbi": 7
}
},
"gameStatus": {},
"allPositions": [
{
"abbreviation": "P"
}
]
},```
parentTeamId is missing. All other players in this file have the parentTeamId within the player. Why not Blubauh :) ?
I understand that all players are either under "home" or "away". So I can retrieve the info from there. I'm still wondering why all players except Blubauh in this response have the id within the player json? Is there a reason the info is not present for this specific player?
I suspect it is because this is the only game he was on the active roster, he was optioned back to their Triple-A team the next day.
If you look at a player who has since been traded, I wonder what their parent team ID would be for a game on their previous team.
Note that this data is coming directly from the API response, and the wrapper has no influence over whether this particular field is included or not.