GabrielPastorello / BRScraper

Python package for Basketball Reference scraping and easy access to basketball data, including NBA, G League and international leagues
MIT License
11 stars 2 forks source link

[BUG] `get_player_stats()` is broken #2

Open a4v2d4 opened 4 hours ago

a4v2d4 commented 4 hours ago

Just tried the example script for NBA (examples_nba.py) and ran into this error when script was in the middle of get_player_stats():

Traceback (most recent call last):
  File "examples_nba.py", line 4, in <module>
    df = nba.get_player_stats('Bruno Caboclo')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/BRScraper/nba.py", line 346, in get_player_stats
    num = df[df['Season']=='Career'].index[0]
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
  File ".venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 5320, in __getitem__
    return getitem(key)
           ^^^^^^^^^^^^
IndexError: index 0 is out of bounds for axis 0 with size 0

Seems issue is with assuming the player's stats table is at index 0 here: df = pd.read_html(url)[0]. I think it should find the table based on the header name "Per Game" or "Totals" instead of assuming same index for each player (diff. players have diff. layouts for diff. reasons).

Most of the rest of the example script works like a charm! Thanks so much for open-sourcing this! Super helpful :)

a4v2d4 commented 3 hours ago

@GabrielPastorello I have a local fix for this -- what is the intended behavior of this function? Get Career stat totals, get Per Game averages for career, or something else?