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
| Parameter | Type | Default | Description |
|---|---|---|---|
season | int | Season year (e.g. 2024); bounded by load_wnba_pbp release availability. | |
return_as_pandas | bool | False | Return 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_name | type | description |
|---|---|---|
game_play_number | Int64 | Game play number |
id | Int64 | Unique play identification number |
sequence_number | Int64 | Sequence number representing a shot-possession (V3 PBP). |
type_id | Int64 | Type identifier (numeric). |
type_text | String | Display text for the type field. |
text | String | Text description of the play / record. |
away_score | Int64 | Away team score at the time of the play. |
home_score | Int64 | Home team score at the time of the play. |
period_number | Int64 | Numeric period (1-4 for quarters; 5+ for OT). |
period_display_value | String | Period display label (e.g. '1st Quarter', 'OT'). |
clock_display_value | String | Game clock display string (e.g. '8:32'). |
scoring_play | Boolean | TRUE if the play resulted in points scored. |
score_value | Int64 | Point value of the play (2 / 3 / 1). |
team_id | Int64 | Unique team identifier. |
athlete_id_1 | Int64 | Primary athlete identifier (e.g. shooter). |
athlete_id_2 | Int64 | Secondary athlete identifier (e.g. assister / fouler). |
athlete_id_3 | Int64 | Athlete id 3. |
wallclock | String | Wallclock. |
shooting_play | Boolean | TRUE if the play was a shooting attempt. |
coordinate_x_raw | Float64 | X coordinate as returned by the API before any adjustment. |
coordinate_y_raw | Float64 | Y coordinate as returned by the API before any adjustment. |
points_attempted | Int64 | |
short_description | String | |
game_id | Int64 | Unique game identifier. |
season | Int64 | Season identifier (4-digit year or 'YYYY-YY' string). |
season_type | Int64 | Season type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats). |
home_team_id | Int64 | Unique identifier for the home team. |
home_team_name | String | Home team name. |
home_team_mascot | String | Home team mascot. |
home_team_abbrev | String | Home team three-letter abbreviation. |
home_team_name_alt | String | Alternate versions of the home team abbreviation |
away_team_id | Int64 | Unique identifier for the away team. |
away_team_name | String | Away team name. |
away_team_mascot | String | Away team mascot. |
away_team_abbrev | String | Away team three-letter abbreviation. |
away_team_name_alt | String | Alternate versions of the away team abbreviation |
game_spread | Float64 | Game spread in (-X Team) format. There are almost none, I would recommend not trusting any of these three columns |
home_favorite | Boolean | Logical (TRUE/FALSE) indicating whether the home team is favored |
game_spread_available | Boolean | Logical (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_spread | Float64 | The game spread with respect to the home team |
qtr | Int64 | Quarter of the game |
time | String | Time left within the period |
clock_minutes | Int64 | Clock minutes split from seconds for developer convenience |
clock_seconds | Float64 | Clock seconds split from minutes for developer convenience |
home_timeout_called | Boolean | |
away_timeout_called | Boolean | |
half | Int64 | Half of the game |
game_half | Int64 | Half of the game |
lag_qtr | Int64 | A lag column on the quarter |
lead_qtr | Int64 | A lead column on the quarter |
lag_half | Int64 | A lag column on the half |
lead_half | Int64 | A lead column on the half |
start_quarter_seconds_remaining | Float64 | Quarter 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_remaining | Float64 | Game 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_remaining | Float64 | Game seconds remaining at the start of the play (''') |
end_quarter_seconds_remaining | Float64 | Quarter seconds remaining at the end of the play (''') |
end_half_seconds_remaining | Float64 | Game half seconds remaining at the end of the play (''') |
end_game_seconds_remaining | Float64 | Game seconds remaining at the end of the play (''') |
period | Int64 | Period of the game (1-4 quarters; 5+ for OT). |
coordinate_x | Float64 | X coordinate on the court (half-court layout). |
coordinate_y | Float64 | Y coordinate on the court (half-court layout). |
game_date | String | Game date (YYYY-MM-DD). |
game_date_time | String | Game start date/time (ISO 8601). |
athlete_name_1 | String | |
athlete_name_2 | String | |
athlete_name_3 | String | |
type_abbreviation | String | Play type abbreviation |
pregame_home_prob | Float64 | |
home_win_prob | Float64 |
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
| Parameter | Type | Default | Description |
|---|---|---|---|
return_as_pandas | bool | False |
Returns
Frame age:Int64, rel_value:Float64, peak_age:Float64.
| col_name | type | description |
|---|---|---|
age | Int64 | Player age (in years). |
rel_value | Float64 | Value 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_age | Float64 | Age 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
| Parameter | Type | Default | Description |
|---|---|---|---|
player_values | DataFrame | Frame player_id, age:Int64, value:Float64. | |
return_as_pandas | bool | False | Return 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
| Parameter | Type | Default | Description |
|---|---|---|---|
draft_year | int | list[int] | A draft year (e.g. 2023) or list of years. | |
return_as_pandas | bool | False | Return 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
| Parameter | Type | Default | Description |
|---|---|---|---|
pbp | DataFrame | ||
pregame_home_prob | float | ||
league_id | str | '10' | |
return_as_pandas | bool | False |
Returns
One row per play: the in_game_features columns plus home_win_prob.
| col_name | type | description |
|---|---|---|
score_diff | Float64 | |
sec_left | Float64 | |
sqrt_sec_left | Float64 | |
pregame_logit | Float64 | |
home_has_ball | Int64 | |
margin_per_sqrt_sec | Float64 | Score 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_60 | Float64 | Square 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_prob | Float64 |
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
| Parameter | Type | Default | Description |
|---|---|---|---|
games | DataFrame | ||
ratings | DataFrame | ||
league_id | str | '10' | |
return_as_pandas | bool | False |
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
| Parameter | Type | Default | Description |
|---|---|---|---|
home_net | float | ||
away_net | float | ||
home_pace | float | ||
away_pace | float | ||
neutral | bool | False | |
league_id | str | '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
| Parameter | Type | Default | Description |
|---|---|---|---|
home_off | float | ||
home_def | float | ||
away_off | float | ||
away_def | float | ||
home_pace | float | ||
away_pace | float | ||
league_id | str | '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
| Parameter | Type | Default | Description |
|---|---|---|---|
draft_year | int | list[int] | A draft year or list of years. | |
return_as_pandas | bool | False | Return 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
| Parameter | Type | Default | Description |
|---|---|---|---|
seasons | Union[int, list[int]] | ||
league_id | str | '10' | |
as_of_date | Union[date, None] | None | |
return_as_pandas | bool | False |
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_name | type | description |
|---|---|---|
season | Int64 | Season identifier (4-digit year or 'YYYY-YY' string). |
team_id | String | Unique team identifier. |
adj_off_rtg | Float64 | |
adj_def_rtg | Float64 | |
adj_net_rtg | Float64 | |
adj_pace | Float64 | |
raw_off_rtg | Float64 | |
raw_def_rtg | Float64 | |
raw_pace | Float64 | |
games | Int64 | Games played. |
rank | Int64 | Rank. |
adj_net_z | Float64 | |
adj_off_rtg_rank | Float64 | Rank 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_rank | Float64 | Rank 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_rank | Float64 | Rank 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_rank | Float64 | Rank 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_rank | Float64 | Rank 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_rank | Float64 | Rank 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_rank | Float64 | Rank 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_pct | Float64 | Percentile 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_pct | Float64 | Percentile 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_pct | Float64 | Percentile 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_pct | Float64 | Percentile 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_pct | Float64 | Percentile 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_pct | Float64 | Percentile 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_pct | Float64 | Percentile 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_n | Int64 | Sample 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_n | Int64 | Sample 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_n | Int64 | Sample 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_n | Int64 | Sample size of adj_pace: the games the pace is computed over (equal to games). |
raw_off_rtg_n | Int64 | Sample 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_n | Int64 | Sample size of raw_def_rtg: the box-score possessions the rating is computed over, summed over the team's games and rounded. |
raw_pace_n | Int64 | Sample 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
| Parameter | Type | Default | Description |
|---|---|---|---|
exp_margin | float | ||
league_id | str | '10' |
Returns
Probability the home team wins, in (0, 1).