zero-sum-seattle / python-mlb-statsapi

Python Wrapper for the MLB's Official Stats API
MIT License
41 stars 10 forks source link

calling get_game_box_score in loop #194

Closed pferreira8 closed 1 year ago

pferreira8 commented 1 year ago

I've attached a screenshot of my traceback, the issue is related to PlayerDictsPerson.init()

I call this function in my if name == main block, and then try to pass the boxscores list into a pd Dataframe after. I am looping through a series of game Ids to try and accomplish this, which is the ["gamepk"] pandas Series ` def get_box_scores(self): boxscores = [] for g in self.game_df["gamepk"]: box = self.api.get_game_box_score(int(g)) boxscores.append(box)

all boxscores of season df

    return boxscores

` It works however if I do a static call like this, Mlb().get_game_box_score(1234556)

Screenshot 2023-06-01 135422

pferreira8 commented 1 year ago

I have added a try-catch to circumvent this error, it now works in this context, just occasionally triggers that TypeError above. I am willing to help contribute to fixing this issue. Screenshot 2023-06-01 140846

pferreira8 commented 1 year ago

after running the loop over the 2023 season to this date, the only gameID that contained an error was 719391

KCNilssen commented 1 year ago

The issue is that Tyler Brown playing for Minnesota here doesn't have a position field. How the dataclass is currently set up requires a position field. This should be an easy fix to make. We will just make position an optional field and that would fix this issue.

  "ID675973": {
          "person": {
            "id": 675973,
            "fullName": "Tyler Brown",
            "link": "/api/v1/people/675973"
          },
          "jerseyNumber": "93",
          "status": {
            "code": "MIN",
            "description": "Minor League Contract"
          },
          "parentTeamId": 117,
          "stats": {},
          "seasonStats": {},
          "gameStatus": {}
  },

Stats, seasonStats, and gameStatus are empty here just to save space while showing you the structure. They are all populated correctly in the real return.

Here is the api endpoint for the boxscore for that specific game: https://statsapi.mlb.com/api/v1/game/719391/boxscore

KCNilssen commented 1 year ago

This should fix your issue. Thanks for the heads up!