Skip to content

Commit

Permalink
Merge pull request #228 from roclark/patch/fix-empty-nba-roster-fields
Browse files Browse the repository at this point in the history
Fix issue pulling empty NBA roster fields
  • Loading branch information
roclark authored Oct 6, 2019
2 parents 9ee2efa + f5c324c commit 0bf8a4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sportsreference/nba/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,8 @@ def _find_players(self, year):
players = page('table#roster tbody tr').items()
for player in players:
player_id = self._get_id(player)
if not player_id or player_id == '':
continue # pragma: no cover
if self._slim:
name = self._get_name(player)
self._players[player_id] = name
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/roster/test_nba_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,3 +1259,16 @@ def test_invalid_default_year_reverts_to_previous_year(self,
for player in roster.players:
assert player.name in ['James Harden', 'Tarik Black',
'Ryan Anderson', 'Trevor Ariza']

@mock.patch('requests.get', side_effect=mock_pyquery)
def test_empty_rows_are_skipped(self, *args, **kwargs):
flexmock(utils) \
.should_receive('_find_year_for_season') \
.and_return('2018')
flexmock(Roster) \
.should_receive('_get_id') \
.and_return(None)

roster = Roster('HOU')

assert len(roster.players) == 0

0 comments on commit 0bf8a4c

Please sign in to comment.