Skip to content

feat: add team conference and division static data#677

Open
madhavcodez wants to merge 1 commit into
swar:masterfrom
madhavcodez:feat/team-conference-division-static-data
Open

feat: add team conference and division static data#677
madhavcodez wants to merge 1 commit into
swar:masterfrom
madhavcodez:feat/team-conference-division-static-data

Conversation

@madhavcodez
Copy link
Copy Markdown

What

Adds two static lookups for NBA team alignment and four helpers to query them.

  • data.team_conferences: team_id -> "East" | "West" (30 NBA teams)
  • data.team_divisions: team_id -> "Atlantic" | "Central" | "Southeast" | "Northwest" | "Pacific" | "Southwest"
  • static.teams.get_team_conference(team_id)
  • static.teams.get_team_division(team_id)
  • static.teams.find_teams_by_conference(conference) (case-insensitive)
  • static.teams.find_teams_by_division(division) (case-insensitive)

WNBA teams are intentionally excluded, matching how get_wnba_teams() is already kept separate.

Why

stats/library/parameters.py already defines Conference and DivisionSimple, but those are input enums for endpoint query params, not a way to ask "which conference is this team in?". There is no existing path from a team_id to its conference or division without hardcoding it in user code.

This fills that gap with the same shape as the existing get_team_by_id / find_teams_by_* helpers, so it reads as a natural extension rather than a new surface.

The string values are deliberately aligned with the param enums, so a typical chain works without remapping:

from nba_api.stats.static import teams
from nba_api.stats.endpoints import leaguestandings

conf = teams.get_team_conference(1610612747)  # Lakers -> "West"
standings = leaguestandings.LeagueStandings(conference_nullable=conf)

Maintenance

NBA conference/division alignment has been stable since the 2004-05 realignment, so this is effectively static reference data with no expected churn.

Tests

14 new unit tests in tests/unit/stats/static/test_static_data.py covering:

  • both dicts contain all 30 NBA team ids
  • values are restricted to the valid conference/division strings
  • conference/division lookups for 6 known teams (parametrized)
  • helpers return None for unknown ids (NBA and WNBA)
  • find_teams_by_* is case-insensitive and returns the right counts (15/15 by conference, 5 per division)
  • East/West sets are disjoint and together cover all 30 NBA team ids (catches a swap that count-only tests would miss)
  • Pacific division has the expected {GSW, LAC, LAL, PHX, SAC} membership
  • division names passed to the conference helper (and vice versa) return [] rather than silently matching
  • falsy input (None, "") is tolerated rather than raising

Full suite: 534 passing locally. The 2 pre-existing tests/unit/live/endpoints/test_get_request_url failures (stale 2021 game id) reproduce on master and are unrelated, as noted in #671 and #676. ruff check and ruff format --check are clean.

Scope

No changes to endpoints, parameters, HTTP layer, or existing helpers. Additive only.

@madhavcodez madhavcodez requested a review from swar as a code owner May 22, 2026 04:50
@madhavcodez
Copy link
Copy Markdown
Author

CI failures are the same pre-existing test_get_request_url cases in tests/unit/live/endpoints/ that hit the live CDN with a stale 2021 game ID. They fail identically on master and were called out in #671 and #676 as unrelated. This PR is additive static data + helpers + tests in stats/static/stats/library — no live endpoints touched.

Local pytest tests/unit/ → 534 passed, same 2 failures. ruff check and ruff format --check clean.

Add team_conferences and team_divisions dicts to stats/library/data.py
mapping the 30 NBA team_ids to their conference and division. WNBA
teams are excluded since the existing teams.get_wnba_teams() set is
already separated and the league has its own alignment.

Add four helpers in stats/static/teams.py:
- get_team_conference(team_id) -> "East" | "West" | None
- get_team_division(team_id)   -> "Atlantic" | "Central" | ... | None
- find_teams_by_conference(conference)  (case-insensitive)
- find_teams_by_division(division)      (case-insensitive)

String values match the existing Conference and DivisionSimple
parameter enums in stats/library/parameters.py so a lookup can be
fed straight back into an endpoint call without remapping.

Adds 14 unit tests (5 structural + 6 parametrized lookup +
disjoint-membership + case-insensitivity + unknown-input) for the
new data and helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant