dblackrun / pbpstats

A package to scrape and parse NBA, WNBA and G-League play-by-play data.
MIT License
86 stars 18 forks source link

Error Loading Recent WNBA game from stats_nba #44

Closed matteosox closed 2 years ago

matteosox commented 2 years ago

Code to reproduce:

from pbpstats.client import Client

settings = {"Possessions": {"source": "web", "data_provider": "stats_nba"}}
game_id = '1022200095'

client = Client(settings)
game = client.Game(game_id)

Results in the following error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Input In [1], in <cell line: 8>()
      5 game_id = '1022200095'
      7 client = Client(settings)
----> 8 game = client.Game(game_id)

File ~/.venv/lib/python3.9/site-packages/pbpstats/objects/game.py:48, in Game.__init__(self, game_id)
     46 source_loader_cls = data_source_map[attr_name]
     47 source_loader = source_loader_cls(self.data_directory)
---> 48 data = data_loader[1](game_id, source_loader)
     49 resource_cls = getattr(self, attr_name)
     50 setattr(
     51     self,
     52     client.PATTERN.sub("_", attr_name).lower(),
     53     resource_cls(data.items),
     54 )

File ~/.venv/lib/python3.9/site-packages/pbpstats/data_loader/stats_nba/possessions/loader.py:73, in StatsNbaPossessionLoader.__init__(self, game_id, source_loader)
     71 self._add_extra_attrs_to_all_possessions()
     72 self._load_bad_possession_overrides()
---> 73 self._check_that_possessions_alternate()

File ~/.venv/lib/python3.9/site-packages/pbpstats/data_loader/stats_nba/possessions/loader.py:101, in StatsNbaPossessionLoader._check_that_possessions_alternate(self)
     99     poss = possession.next_possession
    100     prev_poss = possession
--> 101 if poss.offense_team_id == prev_poss.offense_team_id:
    102     game_id = (
    103         self.game_id if self.league == NBA_STRING else int(self.game_id)
    104     )
    105     if not (
    106         game_id in self.bad_pbp_cases.keys()
    107         and poss.period in self.bad_pbp_cases[game_id].keys()
    108         and poss.number in self.bad_pbp_cases[game_id][poss.period]
    109     ):

File ~/.venv/lib/python3.9/site-packages/pbpstats/resources/possessions/possession.py:144, in Possession.offense_team_id(self)
    138             return (
    139                 team_ids[0]
    140                 if team_ids[1] == prev_event.get_offense_team_id()
    141                 else team_ids[1]
    142             )
    143         return prev_event.get_offense_team_id()
--> 144 return self.events[0].get_offense_team_id()

File ~/.venv/lib/python3.9/site-packages/pbpstats/resources/enhanced_pbp/stats_nba/enhanced_pbp_item.py:178, in StatsEnhancedPbpItem.get_offense_team_id(self)
    174 if isinstance(event_to_check, Rebound) and event_to_check.is_real_rebound:
    175     if not event_to_check.oreb:
    176         return (
    177             team_ids[0]
--> 178             if team_ids[1] == event_to_check.get_offense_team_id()
    179             else team_ids[1]
    180         )
    181     return event_to_check.get_offense_team_id()
    182 if isinstance(event_to_check, (FieldGoal, FreeThrow)):

IndexError: list index out of range

Python 3.9.5 pbpstats==1.3.6 requests==2.27.1

dblackrun commented 2 years ago

You will need to update to the newest version (1.3.7) and also update the missing period starters override file with the starters for the first quarter: "1022200095": {"1": {"1611661321": [203866, 1628277, 204330, 1629481, 1629497], "1611661320": [202633, 1628886, 203014, 1629478, 201911]}},

There is an issue parsing the starters for the first quarter from the pbp for this game and it also does not return any players for the boxscore range request.

matteosox commented 2 years ago

Thanks, that did the trick!