Skip to main content

WNBA — additional Python functions — Models and calculators

build_wnba_season_wp​

build_wnba_season_wp(season: 'int', *, return_as_pandas: 'bool' = False) -> "Union[pl.DataFrame, 'pd.DataFrame']"

A WNBA season's play-by-play with win-probability columns joined in.

Loads the season's play-by-play, schedule, and team boxscores, builds a leakage-free weekly as-of pregame anchor per game from the WNBA ratings engine (league_id="10"), scores every play through the bundled in-game win-probability artifact, and returns the full load_wnba_pbp frame with pregame_home_prob + home_win_prob appended -- the enrich-in-place shape that overwrites the season's play_by_play_<season>.parquet release asset.

Parameters

ParameterTypeDefaultDescription
seasonintSeason year (e.g. 2024); bounded by load_wnba_pbp release availability.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

The season's load_wnba_pbp frame (every column preserved) with the two WP columns pregame_home_prob + home_win_prob appended (both Float64), sorted by game_id then game_play_number.

col_nametypedescription
game_play_numberInt64Game play number
idInt64Unique play identification number
sequence_numberInt64Sequence number representing a shot-possession (V3 PBP).
type_idInt64Type identifier (numeric).
type_textStringDisplay text for the type field.
textStringText description of the play / record.
away_scoreInt64Away team score at the time of the play.
home_scoreInt64Home team score at the time of the play.
period_numberInt64Numeric period (1-4 for quarters; 5+ for OT).
period_display_valueStringPeriod display label (e.g. '1st Quarter', 'OT').
clock_display_valueStringGame clock display string (e.g. '8:32').
scoring_playBooleanTRUE if the play resulted in points scored.
score_valueInt64Point value of the play (2 / 3 / 1).
team_idInt64Unique team identifier.
athlete_id_1Int64Primary athlete identifier (e.g. shooter).
athlete_id_2Int64Secondary athlete identifier (e.g. assister / fouler).
athlete_id_3Int64Athlete id 3.
wallclockStringWallclock.
shooting_playBooleanTRUE if the play was a shooting attempt.
coordinate_x_rawFloat64X coordinate as returned by the API before any adjustment.
coordinate_y_rawFloat64Y coordinate as returned by the API before any adjustment.
points_attemptedInt64
short_descriptionString
game_idInt64Unique game identifier.
seasonInt64Season identifier (4-digit year or 'YYYY-YY' string).
season_typeInt64Season type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats).
home_team_idInt64Unique identifier for the home team.
home_team_nameStringHome team name.
home_team_mascotStringHome team mascot.
home_team_abbrevStringHome team three-letter abbreviation.
home_team_name_altStringAlternate versions of the home team abbreviation
away_team_idInt64Unique identifier for the away team.
away_team_nameStringAway team name.
away_team_mascotStringAway team mascot.
away_team_abbrevStringAway team three-letter abbreviation.
away_team_name_altStringAlternate versions of the away team abbreviation
game_spreadFloat64Game spread in (-X Team) format. There are almost none, I would recommend not trusting any of these three columns
home_favoriteBooleanLogical (TRUE/FALSE) indicating whether the home team is favored
game_spread_availableBooleanLogical (TRUE/FALSE) indicating whether the spread was available from ESPN. Basically, I would just not recommend using any of the spread information, I think I defaulted a lot of them to -2.5 for the home team. Most games probably do not have spread information. This column should really be listed first
home_team_spreadFloat64The game spread with respect to the home team
qtrInt64Quarter of the game
timeStringTime left within the period
clock_minutesInt64Clock minutes split from seconds for developer convenience
clock_secondsFloat64Clock seconds split from minutes for developer convenience
home_timeout_calledBoolean
away_timeout_calledBoolean
halfInt64Half of the game
game_halfInt64Half of the game
lag_qtrInt64A lag column on the quarter
lead_qtrInt64A lead column on the quarter
lag_halfInt64A lag column on the half
lead_halfInt64A lead column on the half
start_quarter_seconds_remainingFloat64Quarter seconds remaining at the start of the play (these are more or less code artifacts from other sports, but may eventually be used more seriously)
start_half_seconds_remainingFloat64Game half seconds remaining at the start of the play (these are more or less code artifacts from other sports, but may eventually be used more seriously)
start_game_seconds_remainingFloat64Game seconds remaining at the start of the play (''')
end_quarter_seconds_remainingFloat64Quarter seconds remaining at the end of the play (''')
end_half_seconds_remainingFloat64Game half seconds remaining at the end of the play (''')
end_game_seconds_remainingFloat64Game seconds remaining at the end of the play (''')
periodInt64Period of the game (1-4 quarters; 5+ for OT).
coordinate_xFloat64X coordinate on the court (half-court layout).
coordinate_yFloat64Y coordinate on the court (half-court layout).
game_dateStringGame date (YYYY-MM-DD).
game_date_timeStringGame start date/time (ISO 8601).
athlete_name_1String
athlete_name_2String
athlete_name_3String
type_abbreviationStringPlay type abbreviation
pregame_home_probFloat64
home_win_probFloat64

Example

from sportsdataverse.wnba import build_wnba_season_wp
wp = build_wnba_season_wp(2024)
wp.select("game_id", "game_play_number", "home_win_prob").head()

# Pandas output

wp_pd = build_wnba_season_wp(2024, return_as_pandas=True)

wnba_aging_curve​

wnba_aging_curve(*, return_as_pandas: 'bool' = False) -> "'pl.DataFrame | pd.DataFrame'"

WNBA aging curve -- the NBA core bound to league="wnba".

See sportsdataverse.nba.nba_aging_curve.nba_aging_curve for the full contract; this is a by-reference re-export, same algorithm, women's bundled artifact.

Parameters

ParameterTypeDefaultDescription
return_as_pandasboolFalse

Returns

Frame age:Int64, rel_value:Float64, peak_age:Float64.

col_nametypedescription
ageInt64Player age (in years).
rel_valueFloat64Value multiplier for this age relative to the peak age: a delta-method curve chaining minutes-weighted within-player consecutive-age changes in per-100-possession box-score value, quadratic-smoothed and min-max scaled to [0.4, 1.0], so the peak age is exactly 1.0 and the lowest-valued age 0.4.
peak_ageFloat64Age at which rel_value reaches its maximum of 1.0, repeated on every row for filtering and joining (29.0 in the bundled curve).

Example

from sportsdataverse.wnba import wnba_aging_curve
curve = wnba_aging_curve()

wnba_career_trajectory​

wnba_career_trajectory(player_values: 'pl.DataFrame', *, return_as_pandas: 'bool' = False) -> "'pl.DataFrame | pd.DataFrame'"

WNBA career trajectory -- the NBA core bound to league="wnba".

See sportsdataverse.nba.nba_aging_curve.nba_career_trajectory for the full contract.

Parameters

ParameterTypeDefaultDescription
player_valuesDataFrameFrame player_id, age:Int64, value:Float64.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

player_values plus age_adjusted_value and proj_next_value.

No returns table is published for this function: no capture: its input is a user-built player-age panel (player_id, age, value) that no package function produces.

Example

import polars as pl
from sportsdataverse.wnba import wnba_career_trajectory
player_values = pl.DataFrame({"player_id": ["1"], "age": [26], "value": [10.0]})
wnba_career_trajectory(player_values)

wnba_draft_model​

wnba_draft_model(draft_year: "'int | list[int]'", *, return_as_pandas: 'bool' = False) -> "'pl.DataFrame | pd.DataFrame'"

Project WNBA prospect career value + draft probability from draft slot.

Parameters

ParameterTypeDefaultDescription
draft_yearint | list[int]A draft year (e.g. 2023) or list of years.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

Frame player_id:Utf8, draft_year:Int64, proj_career_value:Float64, draft_prob:Float64, projected_pick:Int64, pro_tier:Utf8. Empty input returns the zero-row schema, never raises.

No returns table is published for this function: no capture: it reads stats.wnba.com, which answers HTTP 403 to the datacenter IP the docs are built on; the function works from a residential IP.

Example

from sportsdataverse.wnba import wnba_draft_model
board = wnba_draft_model(2023)

wnba_in_game_win_prob​

wnba_in_game_win_prob(pbp: 'pl.DataFrame', pregame_home_prob: 'float', *, league_id: 'str' = '10', return_as_pandas: 'bool' = False) -> 'Union[pl.DataFrame, pd.DataFrame]'

WNBA in-game win probability (league_id='10'). See sportsdataverse.nba.nba_game_predict.nba_in_game_win_prob.

Parameters

ParameterTypeDefaultDescription
pbpDataFrame
pregame_home_probfloat
league_idstr'10'
return_as_pandasboolFalse

Returns

One row per play: the in_game_features columns plus home_win_prob.

col_nametypedescription
score_diffFloat64
sec_leftFloat64
sqrt_sec_leftFloat64
pregame_logitFloat64
home_has_ballInt64
margin_per_sqrt_secFloat64Score margin over the time left, score_diff / sqrt(sec_left + 1): a fixed lead grows as the clock runs down. The basketball in-game boosters read the final minute only through this column.
sqrt_sec_left_60Float64Square root of the seconds left, floored at one minute (sqrt(max(sec_left, 60))): the clock the basketball in-game boosters read outside the final minute.
home_win_probFloat64

wnba_predict_games​

wnba_predict_games(games: 'pl.DataFrame', ratings: 'pl.DataFrame', *, league_id: 'str' = '10', return_as_pandas: 'bool' = False) -> 'Union[pl.DataFrame, pd.DataFrame]'

WNBA vectorized pregame predictions (league_id='10'). See sportsdataverse.nba.nba_game_predict.nba_predict_games.

Parameters

ParameterTypeDefaultDescription
gamesDataFrame
ratingsDataFrame
league_idstr'10'
return_as_pandasboolFalse

Returns

One row per input game: game_id, home_team_id, away_team_id, exp_margin, home_win_prob, exp_total. Games whose teams are missing from ratings carry nulls.

No returns table is published for this function: no capture: it needs one row per game with string home_team_id / away_team_id matching wnba_team_ratings.team_id, and every package schedule carries integer ids.

wnba_predict_margin​

wnba_predict_margin(home_net: 'float', away_net: 'float', *, home_pace: 'float', away_pace: 'float', neutral: 'bool' = False, league_id: 'str' = '10') -> 'float'

WNBA expected margin (league_id='10'). See sportsdataverse.nba.nba_game_predict.predict_margin.

Parameters

ParameterTypeDefaultDescription
home_netfloat
away_netfloat
home_pacefloat
away_pacefloat
neutralboolFalse
league_idstr'10'

Returns

Expected margin in points (positive favors the home team).

wnba_predict_total​

wnba_predict_total(home_off: 'float', home_def: 'float', away_off: 'float', away_def: 'float', home_pace: 'float', away_pace: 'float', *, league_id: 'str' = '10') -> 'float'

WNBA expected total (league_id='10'). See sportsdataverse.nba.nba_game_predict.predict_total.

Parameters

ParameterTypeDefaultDescription
home_offfloat
home_deffloat
away_offfloat
away_deffloat
home_pacefloat
away_pacefloat
league_idstr'10'

Returns

Expected combined points scored by both teams.

wnba_rookie_projection​

wnba_rookie_projection(draft_year: "'int | list[int]'", *, return_as_pandas: 'bool' = False) -> "'pl.DataFrame | pd.DataFrame'"

WNBA rookie/sophomore projection -- composes the WNBA draft/aging/availability pieces.

Parameters

ParameterTypeDefaultDescription
draft_yearint | list[int]A draft year or list of years.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

Frame player_id:Utf8, draft_year:Int64, proj_rookie_value:Float64, proj_soph_value:Float64, proj_rookie_min:Float64, proj_avail_pct:Float64, pro_tier:Utf8. Empty input -> zero-row schema.

No returns table is published for this function: no capture: it reads stats.wnba.com, which answers HTTP 403 to the datacenter IP the docs are built on; the function works from a residential IP.

Example

from sportsdataverse.wnba import wnba_rookie_projection
board = wnba_rookie_projection(2023)

wnba_team_ratings​

wnba_team_ratings(seasons: 'Union[int, list[int]]', *, league_id: 'str' = '10', as_of_date: 'Union[dt.date, None]' = None, return_as_pandas: 'bool' = False) -> "Union[pl.DataFrame, 'pd.DataFrame']"

WNBA team ratings (league_id='10'). See sportsdataverse.nba.nba_team_ratings.nba_team_ratings.

Parameters

ParameterTypeDefaultDescription
seasonsUnion[int, list[int]]
league_idstr'10'
as_of_dateUnion[date, None]None
return_as_pandasboolFalse

Returns

One row per (season, team_id): season, team_id, adj_off_rtg, adj_def_rtg, adj_net_rtg, adj_pace, raw_off_rtg, raw_def_rtg, raw_pace, games, rank, adj_net_z, then <m>_rank, <m>_pct and <m>_n for each of the seven ratings (BB-D2, the football F5/F6 grammar of sportsdataverse._common.league_context). _rank is 1 for the best team in the season: the highest offensive and net ratings, the lowest *_def_rtg, the fastest pace. _pct is the Weibull percentile. Both are null for a team under half the season's most games, and for every team when fewer than five qualifying teams have the rating or they all share one value. On a full season the half-games rule drops the All-Star teams; with as_of_date the most games is taken before the cut, so an early cut can also null regular teams. _n counts the sample: possessions (rounded) for the ratings, games for the paces. Empty input returns that schema with zero rows.

col_nametypedescription
seasonInt64Season identifier (4-digit year or 'YYYY-YY' string).
team_idStringUnique team identifier.
adj_off_rtgFloat64
adj_def_rtgFloat64
adj_net_rtgFloat64
adj_paceFloat64
raw_off_rtgFloat64
raw_def_rtgFloat64
raw_paceFloat64
gamesInt64Games played.
rankInt64Rank.
adj_net_zFloat64
adj_off_rtg_rankFloat64Rank of adj_off_rtg, the opponent-adjusted offensive rating (points scored per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the highest value ranks 1, average ties.
adj_def_rtg_rankFloat64Rank of adj_def_rtg, the opponent-adjusted defensive rating (points allowed per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the lowest value ranks 1 (fewer points allowed is better), average ties.
adj_net_rtg_rankFloat64Rank of adj_net_rtg, the opponent-adjusted net rating (adj_off_rtg minus adj_def_rtg), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the highest value ranks 1, average ties.
adj_pace_rankFloat64Rank of adj_pace, the opponent-adjusted pace (possessions per game), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the fastest team ranks 1 (pace has no good direction), average ties.
raw_off_rtg_rankFloat64Rank of raw_off_rtg, the unadjusted offensive rating (points scored per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the highest value ranks 1, average ties.
raw_def_rtg_rankFloat64Rank of raw_def_rtg, the unadjusted defensive rating (points allowed per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the lowest value ranks 1 (fewer points allowed is better), average ties.
raw_pace_rankFloat64Rank of raw_pace, the unadjusted pace (possessions per game), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify; the fastest team ranks 1 (pace has no good direction), average ties.
adj_off_rtg_pctFloat64Percentile of adj_off_rtg, the opponent-adjusted offensive rating (points scored per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
adj_def_rtg_pctFloat64Percentile of adj_def_rtg, the opponent-adjusted defensive rating (points allowed per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
adj_net_rtg_pctFloat64Percentile of adj_net_rtg, the opponent-adjusted net rating (adj_off_rtg minus adj_def_rtg), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
adj_pace_pctFloat64Percentile of adj_pace, the opponent-adjusted pace (possessions per game), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
raw_off_rtg_pctFloat64Percentile of raw_off_rtg, the unadjusted offensive rating (points scored per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
raw_def_rtg_pctFloat64Percentile of raw_def_rtg, the unadjusted defensive rating (points allowed per 100 possessions), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
raw_pace_pctFloat64Percentile of raw_pace, the unadjusted pace (possessions per game), among the season's qualified teams (at least half the most games any team played, which leaves out the one-game All-Star teams); null for a non-qualifier or when fewer than five teams qualify: 100 * (n + 1 - rank) / (n + 1) with n the ranked teams, so the best team sits near 100 and none is exactly 0 or 100.
adj_off_rtg_nInt64Sample size of adj_off_rtg: the box-score possessions the rating is computed over, summed over the team's games and rounded.
adj_def_rtg_nInt64Sample size of adj_def_rtg: the box-score possessions the rating is computed over, summed over the team's games and rounded.
adj_net_rtg_nInt64Sample size of adj_net_rtg: the box-score possessions the rating is computed over on both ends (offense plus defense, twice the possession estimate), summed over the team's games and rounded.
adj_pace_nInt64Sample size of adj_pace: the games the pace is computed over (equal to games).
raw_off_rtg_nInt64Sample size of raw_off_rtg: the box-score possessions the rating is computed over, summed over the team's games and rounded.
raw_def_rtg_nInt64Sample size of raw_def_rtg: the box-score possessions the rating is computed over, summed over the team's games and rounded.
raw_pace_nInt64Sample size of raw_pace: the games the pace is computed over (equal to games).

wnba_win_prob_from_margin​

wnba_win_prob_from_margin(exp_margin: 'float', *, league_id: 'str' = '10') -> 'float'

WNBA home win probability (league_id='10'). See sportsdataverse.nba.nba_game_predict.win_prob_from_margin.

Parameters

ParameterTypeDefaultDescription
exp_marginfloat
league_idstr'10'

Returns

Probability the home team wins, in (0, 1).