Skip to main content

Women's college basketball — additional Python functions — Play-by-play processing

build_athlete_identity_lookup​

build_athlete_identity_lookup(rosters: 'dict[int | str, dict]') -> 'dict[str, dict[str, Any]]'

R build_athlete_identity_lookup: athlete_id -> identity from team rosters.

Parameters

ParameterTypeDefaultDescription
rostersdict[int | str, dict]Mapping of team_id -> that team's raw roster payload (wbb/team_rosters/json/{season}/{team_id}.json). NOTE: R walks raw$athletes directly here (no position-bucket unwrap, unlike the rosters dataset itself).

Returns

athlete_id (str) -> identity fields for helper_wbb_player_season_stats.

classify_point_value​

classify_point_value(dist_ft: 'float', x: 'float', y: 'float', *, league: 'str', season: 'int') -> 'int'

2 or 3 from basket-relative geometry (arc radius + corner band).

Parameters

ParameterTypeDefaultDescription
dist_ftfloatEuclidean distance from the basket, feet.
xfloatLateral offset from the basket, feet (baseline direction).
yfloatDistance up-court from the basket, feet.
leaguestr"mens" or "womens".
seasonintSeason-ending year (selects the arc era).

Returns

3 at/beyond the arc or in the corner band, else 2.

Example

from sportsdataverse.mbb.mbb_shots_adapter import classify_point_value
classify_point_value(24.0, 0.0, 24.0, league="mens", season=2020)

classify_zone_geometry​

classify_zone_geometry(dist_ft: 'float', x: 'float', y: 'float', *, league: 'str', season: 'int') -> 'str'

Shot zone from geometry: rim | paint | mid | corner3 | abovebreak3.

Parameters

ParameterTypeDefaultDescription
dist_ftfloatEuclidean distance from the basket, feet.
xfloatLateral offset from the basket, feet.
yfloatDistance up-court from the basket, feet.
leaguestr"mens" or "womens".
seasonintSeason-ending year (selects the arc era).

Returns

One of rim, paint, mid, corner3, abovebreak3.

Example

from sportsdataverse.mbb.mbb_shots_adapter import classify_zone_geometry
classify_zone_geometry(2.0, 0.0, 2.0, league="mens", season=2020)

classify_zone_type​

classify_zone_type(type_text: "'str | None'") -> "'str | None'"

Collapse a source shot-type label to rim | arc3 | jump.

Note: the 2025+ ESPN shots release carries NO three-point marker in type_text (vocabulary is JumpShot/LayUpShot/DunkShot/TipShot), so arc3 typically comes from geometry/score_value there; the branch exists for sources that do label threes.

Parameters

ParameterTypeDefaultDescription
type_textstr | NoneSource label (e.g. "DunkShot"); None passes through.

Returns

rim, arc3, jump, or None for null input.

Example

from sportsdataverse.mbb.mbb_shots_adapter import classify_zone_type
classify_zone_type("DunkShot")

espn_shots_to_canonical​

espn_shots_to_canonical(espn: 'pl.DataFrame', *, league: 'str', season: 'int', scale: "'tuple[float, float, float] | None'" = None) -> 'pl.DataFrame'

ESPN load_mbb_shots frame -> the canonical shot frame.

Field-goal attempts only (free throws and sentinel-coordinate rows are dropped). point_value comes from score_value -- the release populates it on misses too, and its type_text carries NO three-point marker, so arc3 is value-derived. Coordinates are re-based to the fitted basket origin and scaled to feet.

Parameters

ParameterTypeDefaultDescription
espnDataFrameload_mbb_shots-shaped frame.
leaguestr"mens" or "womens".
seasonintSeason-ending year.
scaletuple[float, float, float] | NoneNoneOptional pre-fitted (origin_x, origin_y, feet_per_unit); fitted from espn when None.

Returns

The canonical shot frame (CANONICAL_SHOT_SCHEMA); empty input returns the zero-row schema.

col_nametypedescription
game_idStringUnique game identifier.
seasonInt64Season identifier (4-digit year or 'YYYY-YY' string).
team_idStringUnique team identifier.
shooter_idStringUnique identifier for shooter.
shot_xFloat64
shot_yFloat64
dist_ftFloat64
shot_zoneString
shot_typeStringShot type label (e.g. 'Jump Shot', 'Layup').
madeBoolean
point_valueInt64
periodInt64Period of the game (1-4 quarters; 5+ for OT).
sec_leftFloat64
sourceString

Example

from sportsdataverse.mbb.mbb_loaders import load_mbb_shots
from sportsdataverse.mbb.mbb_shots_adapter import espn_shots_to_canonical
df = espn_shots_to_canonical(load_mbb_shots([2025]), league="mens", season=2025)

fit_espn_court_scale​

fit_espn_court_scale(espn: 'pl.DataFrame', *, league: 'str', season: 'int') -> "'tuple[float, float, float]'"

Fit the ESPN raw-coordinate court scale: (origin_x, origin_y, feet_per_unit).

The release's coordinate_{x,y}_raw grid is basket-anchored half-court (width 0-50, rim cluster near (25, 2)). Origin = median raw coordinates of made rim-type shots; feet_per_unit = arc radius / median unit-distance of made threes from that origin -- fitted, not guessed, so a units change in the release shows up as a scale shift.

Parameters

ParameterTypeDefaultDescription
espnDataFrameload_mbb_shots-shaped frame.
leaguestr"mens" or "womens".
seasonintSeason-ending year (selects the arc radius).

Returns

(origin_x, origin_y, feet_per_unit); documented fallbacks (25.0, 2.0, 1.0) when either calibration subset is empty.

Example

from sportsdataverse.mbb.mbb_shots_adapter import fit_espn_court_scale
scale = fit_espn_court_scale(espn, league="mens", season=2025)

infer_wbb_period_model​

infer_wbb_period_model(html: 'str') -> "'tuple[int, int, int]'"

Tell a halves-era WBB page from a quarters-era one by its first-period clock.

stats.ncaa.org serves one table per period after the line score; the first period table's clock column runs down from 20:00 in a halves game and from 10:00 in a quarters game, so any clock above 600 seconds identifies the halves era. The line-score width alone cannot (halves + 2 OT and quarters

  • 0 OT both have six columns).

Parameters

ParameterTypeDefaultDescription
htmlstrThe raw play-by-play page.

Returns

(2, 1200, 300) when a first-period clock above 10:00 is present, otherwise the quarters model (an unreadable page falls through to the modern model, matching ~sportsdataverse.scrape.ncaa.parse.wbb_period_model).

Example

from sportsdataverse.wbb.wbb_ncaa_game_pbp import infer_wbb_period_model
infer_wbb_period_model(open("pbp_1613299.html").read()) # (2, 1200, 300)

ncaa_wbb_game_pbp​

ncaa_wbb_game_pbp(game_id: 'object', *, season: 'Optional[object]' = None, fetcher: 'Optional[_SupportsFetchGamePbp]' = None, return_as_pandas: 'bool' = False) -> "Union[pl.DataFrame, 'pd.DataFrame']"

Scrape one WBB game's play-by-play (wbigballR scrape_game, era-aware).

Same engine as sportsdataverse.mbb.mbb_ncaa_game_pbp.ncaa_mbb_game_pbp with the WBB period model for the game's era bound: halves through 2014-15, quarters from 2015-16 (see the module docstring).

Parameters

ParameterTypeDefaultDescription
game_idobjectNCAA contest id (e.g. "5722355").
seasonOptional[object]NoneSeason as an ending year (2015) or span ("2014-15"). When omitted, NaN or blank, the era is inferred from the page's first-period clock (infer_wbb_period_model).
fetcherOptional[_SupportsFetchGamePbp]NoneOptional injected fetcher exposing fetch_game_pbp (for tests/offline use). Defaults to a fresh NcaaFetcher.with_browser() context per call.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

The 35-column play-by-play frame (zero rows when the game is not found).

col_nametypedescription
game_idStringUnique game identifier.
game_dateStringGame date (YYYY-MM-DD).
homeStringHome.
awayStringAway record.
periodInt64Period of the game (1-4 quarters; 5+ for OT).
clockStringGame clock value.
game_timeStringGame start time.
game_secondsInt64
home_scoreInt64Home team score at the time of the play.
away_scoreInt64Away team score at the time of the play.
event_teamString
event_descriptionString
player_1String
player_2String
event_typeStringEvent / play type code (V2 PBP).
event_resultString
shot_valueInt64Point value of the shot (2 or 3).
event_lengthInt64
poss_numInt64
poss_teamString
poss_lengthInt64
is_transitionBoolean
home_1String
home_2String
home_3String
home_4String
home_5String
away_1String
away_2String
away_3String
away_4String
away_5String
statusStringStatus label.
is_garbage_timeBoolean
sub_deviateInt64

Raises

ExceptionDescription
ValueErrorgame_id is not an integral contest id (None, NaN, 5722355.5); a float such as 5722355.0 is accepted.

Example

from sportsdataverse.wbb.wbb_ncaa_game_pbp import ncaa_wbb_game_pbp
df = ncaa_wbb_game_pbp("5722355")
print(df.shape)

# Pin the era explicitly for a 2014-15 (halves) game

df = ncaa_wbb_game_pbp("1613299", season=2015)

ncaa_wbb_play_by_play​

ncaa_wbb_play_by_play(game_ids: 'Sequence[object]', *, season: 'Optional[object]' = None, fetcher: 'Optional[_SupportsFetchGamePbp]' = None, return_as_pandas: 'bool' = False, errors: "Literal['raise', 'skip']" = 'raise') -> "Union[pl.DataFrame, 'pd.DataFrame']"

Scrape many WBB games' play-by-play (wbigballR get_play_by_play, era-aware).

Same driver as sportsdataverse.mbb.mbb_ncaa_game_pbp.ncaa_mbb_play_by_play (drop missing ids, shared fetcher session, one retry per empty or failed scrape except a page the format guard rejected) with the WBB period model for each game's era bound.

Parameters

ParameterTypeDefaultDescription
game_idsSequence[object]NCAA contest ids; None/NaN entries and non-integral floats (5722355.5) are dropped, an integral float (5722355.0) is read as "5722355".
seasonOptional[object]NoneSeason shared by every id, as an ending year or span. When omitted, NaN or blank, each page's era is inferred from its first-period clock, so ids from both eras may be mixed.
fetcherOptional[_SupportsFetchGamePbp]NoneOptional injected fetcher exposing fetch_game_pbp. Defaults to one shared NcaaFetcher.with_browser() context.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.
errorsLiteral['raise', 'skip']'raise'"raise" (default): a failed fetch (a ban, an exhausted proxy pool, an uncleared challenge) raises AssetFetchError. "skip": it is dropped like a missing game, and the frame gains a scrape_status column -- "ok" on every play row, plus one row per dropped game (game_id and why: fetch_failed: ..., no_data: ..., request_error: ..., parse_failed: ... or empty).

Returns

Row-bound play-by-play for every game that scraped successfully (zero-row contract frame when none did).

col_nametypedescription
game_idStringUnique game identifier.
game_dateStringGame date (YYYY-MM-DD).
homeStringHome.
awayStringAway record.
periodInt64Period of the game (1-4 quarters; 5+ for OT).
clockStringGame clock value.
game_timeStringGame start time.
game_secondsInt64
home_scoreInt64Home team score at the time of the play.
away_scoreInt64Away team score at the time of the play.
event_teamString
event_descriptionString
player_1String
player_2String
event_typeStringEvent / play type code (V2 PBP).
event_resultString
shot_valueInt64Point value of the shot (2 or 3).
event_lengthInt64
poss_numInt64
poss_teamString
poss_lengthInt64
is_transitionBoolean
home_1String
home_2String
home_3String
home_4String
home_5String
away_1String
away_2String
away_3String
away_4String
away_5String
statusStringStatus label.
is_garbage_timeBoolean
sub_deviateInt64

Raises

ExceptionDescription
AssetFetchErrorA fetch failed and errors="raise".
ValueErrorerrors is not "raise" or "skip".

Example

from sportsdataverse.wbb.wbb_ncaa_game_pbp import ncaa_wbb_play_by_play
df = ncaa_wbb_play_by_play(["5722355", "5732292"])
print(df.shape)

shot_events_to_frame​

shot_events_to_frame(events: 'list[ShotEvent]', *, season: 'int', league: 'str' = 'mens') -> 'pl.DataFrame'

Flatten NCAA HTML ShotEvent objects to the canonical frame.

The NCAA SVG shot maps carry location + made/miss but no shot-type label (shot_type = "unknown"); point_value/shot_zone come from the geometry classifiers. The parser-phase pts field is the MADE flag (1/0), not the point value.

Parameters

ParameterTypeDefaultDescription
eventslist[ShotEvent]Parsed shot events (create_shot_event_data output).
seasonintSeason-ending year the events belong to.
leaguestr'mens'"mens" or "womens".

Returns

The canonical shot frame (CANONICAL_SHOT_SCHEMA); empty input returns the zero-row schema.

col_nametypedescription
game_idStringUnique game identifier.
seasonInt64Season identifier (4-digit year or 'YYYY-YY' string).
team_idStringUnique team identifier.
shooter_idStringUnique identifier for shooter.
shot_xFloat64
shot_yFloat64
dist_ftFloat64
shot_zoneString
shot_typeStringShot type label (e.g. 'Jump Shot', 'Layup').
madeBoolean
point_valueInt64
periodInt64Period of the game (1-4 quarters; 5+ for OT).
sec_leftFloat64
sourceString

Example

from sportsdataverse.mbb.mbb_shots_adapter import shot_events_to_frame
df = shot_events_to_frame(events, season=2025)

wbb_pbp_disk​

wbb_pbp_disk(game_id, path_to_json)

Read a saved ESPN WBB play-by-play payload from disk.

Parameters

ParameterTypeDefaultDescription
game_idThe ESPN game id; the file read is {game_id}.json.
path_to_jsonThe directory holding the saved payloads.

Returns

The payload exactly as saved (the raw ESPN summary JSON), ready for helper_wbb_pbp.

Raises

ExceptionDescription
FileNotFoundErrorThere is no {game_id}.json in path_to_json.