Skip to content

_sort_results raises KeyError when every game in a bulk scrape fails #89

Closed

Description

@dcstats

Latent bug (pre-2.2.0, not a regression)

The bulk scrapers (`get_games_range`, `get_games_team`, `get_games_conference`) end with `_sort_results`, which sorts the info frame by `['game_datetime', 'game_id']` (src/cbbpy/utils/cbbpy_utils.py:279). When game IDs exist but every `_get_game` call returns empty frames (e.g. ESPN outage, WAF blocking, all games 404), `pd.concat` of the empty `pd.DataFrame([])` results yields an empty frame with no columns, and `sort_values` raises `KeyError: 'game_datetime'` instead of returning three empty DataFrames.

Master had the same hole (it sorted by `game_day`/`game_time`), so this is not a 2.2.0 regression — but #83 was specifically about failure-path return types, and this is the remaining gap.

Fix

In `_sort_results`, skip sorting any frame that is empty (or lacks the sort columns), so the all-failures path returns `(empty, empty, empty)` like the no-games path does. Add an offline test where every game fetch fails.

Activity

  1. self-assigned this
    on Jul 22, 2026
  2. added this to the v2.2.0 milestone on Jul 22, 2026
  3. added a commit that references this issue on Jul 23, 2026
  4. dcstats commented on Jul 23, 2026

    @dcstats
    OwnerAuthor

    fixed with fc25f6f

  5. linked a pull request that will close this issue2.2.0 #94on Jul 29, 2026
  6. removed a link to a pull request2.2.0 #94on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething is incorrect or brokenpriority: mediumShould fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions