davidjkrause / sportsipy

A free sports API written for python
MIT License
31 stars 8 forks source link

Error getting Boxscore().dataframe #3

Closed jack11wagner closed 11 months ago

jack11wagner commented 11 months ago

Describe the bug Getting an error when trying to get a dataframe of a boxscore Boxscore("202311170NOP").dataframe

Here is the full stack trace. Not sure whats going on here. Seems like the URI link is invalid?

TypeError                                 Traceback (most recent call last)
[/var/folders/t2/tydlk74s2hjf3xvc375z5fq40000gn/T/ipykernel_76390/888226579.py](https://file+.vscode-resource.vscode-cdn.net/var/folders/t2/tydlk74s2hjf3xvc375z5fq40000gn/T/ipykernel_76390/888226579.py) in <module>
----> 1 Boxscore("202311170NOP").dataframe

[~/PersonalProjects/SportsBettingProject/venv/lib/python3.8/site-packages/sportsipy/nba/boxscore.py](https://file+.vscode-resource.vscode-cdn.net/Users/jack11wagner/PersonalProjects/SportsBettingProject/NBA/~/PersonalProjects/SportsBettingProject/venv/lib/python3.8/site-packages/sportsipy/nba/boxscore.py) in dataframe(self)
    780             'home_wins': self.home_wins,
    781             'location': self.location,
--> 782             print("UR MOM")
    783             # 'losing_abbr': self.losing_abbr,
    784             # 'losing_name': self.losing_name,

[~/PersonalProjects/SportsBettingProject/venv/lib/python3.8/site-packages/sportsipy/nba/boxscore.py](https://file+.vscode-resource.vscode-cdn.net/Users/jack11wagner/PersonalProjects/SportsBettingProject/NBA/~/PersonalProjects/SportsBettingProject/venv/lib/python3.8/site-packages/sportsipy/nba/boxscore.py) in losing_abbr(self)
    881         for the Phoenix Suns.
    882         """
--> 883         if self.winner == HOME:
    884             return utils._parse_abbreviation(self._away_name)
    885         return utils._parse_abbreviation(self._home_name)

[~/PersonalProjects/SportsBettingProject/venv/lib/python3.8/site-packages/sportsipy/utils.py](https://file+.vscode-resource.vscode-cdn.net/Users/jack11wagner/PersonalProjects/SportsBettingProject/NBA/~/PersonalProjects/SportsBettingProject/venv/lib/python3.8/site-packages/sportsipy/utils.py) in _parse_abbreviation(uri_link)
    149         The shortened uppercase abbreviation for a given team.
    150     """
--> 151     abbr = re.sub(r'/[0-9]+\..*htm.*', '', uri_link('a').attr('href'))
    152     abbr = re.sub(r'/.*/schools/', '', abbr)
    153     abbr = re.sub(r'/teams/', '', abbr)
...
--> 210     return _compile(pattern, flags).sub(repl, string, count)
    211 
    212 def subn(pattern, repl, string, count=0, flags=0):

TypeError: expected string or bytes-like object

To Reproduce Boxscore("202311170NOP").dataframe

Expected behavior

A Boxscore dataframe of the Boxscore id

jack11wagner commented 11 months ago

I am new to using this package but looking at the vars, it seems there are a few important variables with incomplete records

Code ran: vars(Boxscore("202311170NOP"))

Returned:

`{'_uri': '202311170NOP',
 '_date': 'In-Season Tournament',
 '_location': '8:00 PM, November 17, 2023',
 '_home_name': [],
 '_away_name': [],
 '_winner': None,
 '_winning_name': None,
 '_winning_abbr': None,
 '_losing_name': None,
 '_losing_abbr': None,
 '_pace': '101.3',
 '_summary': {'away': [28, 25, 33, 24], 'home': [36, 33, 26, 20]},
 '_away_record': 'Denver Nuggets Basic and Advanced Stats',
 '_away_minutes_played': '240',
 '_away_field_goals': '47',
 '_away_field_goal_attempts': '96',
 '_away_field_goal_percentage': '.490',
 '_away_three_point_field_goals': '10',
 '_away_three_point_field_goal_attempts': '40',
 '_away_three_point_field_goal_percentage': '.250',
 '_away_free_throws': '6',
 '_away_free_throw_attempts': '12',
 '_away_free_throw_percentage': '.500',
 '_away_offensive_rebounds': '11',
 '_away_defensive_rebounds': '40',
 '_away_total_rebounds': '51',
 '_away_assists': '37',
 '_away_steals': '4',
 '_away_blocks': '3',
 '_away_turnovers': '13',
 '_away_personal_fouls': '20',
 '_away_points': '110',
 '_away_true_shooting_percentage': '.543',
 '_away_effective_field_goal_percentage': '.542',
 '_away_three_point_attempt_rate': '.417',
 '_away_free_throw_attempt_rate': '.125',
 '_away_offensive_rebound_percentage': '23.9',
 '_away_defensive_rebound_percentage': '90.9',
 '_away_total_rebound_percentage': '56.7',
 '_away_assist_percentage': '78.7',
 '_away_steal_percentage': '3.9',
 '_away_block_percentage': '4.6',
 '_away_turnover_percentage': '11.4',
 '_away_offensive_rating': '108.6',
 '_away_defensive_rating': '113.5',
 '_home_record': 'New Orleans Pelicans (H2)',
 '_home_minutes_played': '240',
 '_home_field_goals': '46',
 '_home_field_goal_attempts': '88',
 '_home_field_goal_percentage': '.523',
 '_home_three_point_field_goals': '12',
 '_home_three_point_field_goal_attempts': '23',
 '_home_three_point_field_goal_percentage': '.522',
 '_home_free_throws': '11',
 '_home_free_throw_attempts': '21',
 '_home_free_throw_percentage': '.524',
 '_home_offensive_rebounds': '4',
 '_home_defensive_rebounds': '35',
 '_home_total_rebounds': '39',
 '_home_assists': '33',
 '_home_steals': '8',
 '_home_blocks': '5',
 '_home_turnovers': '9',
 '_home_personal_fouls': '13',
 '_home_points': '115',
 '_home_true_shooting_percentage': '.591',
 '_home_effective_field_goal_percentage': '.591',
 '_home_three_point_attempt_rate': '.261',
 '_home_free_throw_attempt_rate': '.239',
 '_home_offensive_rebound_percentage': '9.1',
 '_home_defensive_rebound_percentage': '76.1',
 '_home_total_rebound_percentage': '43.3',
 '_home_assist_percentage': '71.7',
 '_home_steal_percentage': '7.9',
 '_home_block_percentage': '8.9',
 '_home_turnover_percentage': '8.5',
 '_home_offensive_rating': '113.5',
 '_home_defensive_rating': '108.6',
 '_away_players': [<sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5430>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52b821d60>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5550>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5700>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5250>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e57f0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5c10>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5340>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5df0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5670>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27b50>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27100>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27670>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf277f0>],
 '_home_players': [<sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf271f0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27550>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27ca0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf3b400>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf3b220>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf3bac0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf3b850>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf3b880>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27bb0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52bf27910>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e56d0>,
  <sportsipy.nba.boxscore.BoxscorePlayer at 0x7ff52f9e5ac0>]}
jack11wagner commented 11 months ago

I ended up creating my own function to fill in the holes for the various columns missing, however this still is an issue.

davidjkrause commented 11 months ago

The source data format changed, so some updates were made on https://github.com/davidjkrause/sportsipy/pull/4, including updating the tests and making sure they pass.

The change was merged to master, please try it and let me know if it works for you.