Skip to main content
Version: 0.2.0

NBA — additional Python functions — Models and calculators: nba_player–nba_team

nba_player_impact_context​

nba_player_impact_context(impact: 'pl.DataFrame', *, league_id: 'str' = '00', return_as_pandas: 'bool' = False) -> 'pl.DataFrame | pd.DataFrame'

Append <m>_n, <m>_rank and <m>_pct to a player_impact table.

Ranks are computed within (season, season_type) over the players whose <m>_n reaches the metric's gate (module docstring); a playoff run rarely reaches the regular-season gates, so most playoff ranks are null. A row's rank and percentile are also null when its metric is null or non-finite, when its season or season_type is null, when fewer than ~sportsdataverse._common.league_context.MIN_COHORT_PLAYERS players qualify in the group, or when every qualifying value in the group is equal. Nothing is dropped, and running it on its own output gives the same frame.

Parameters

ParameterTypeDefaultDescription
impactDataFrameA player_impact table: season, season_type, off_poss, def_poss and the 16 metrics of IMPACT_RANKED, one row per player, season and season type.
league_idstr'00'"00" NBA or "10" WNBA, which picks the sample gates.
return_as_pandasboolFalseReturn a pandas.DataFrame instead of polars.

Returns

impact with <m>_n (Int64), then <m>_rank and <m>_pct (Float64) appended for every metric of IMPACT_RANKED, in that order.

col_nametypedescription
player_idInt64Unique player identifier.
player_nameStringPlayer name.
team_idInt64Unique team identifier.
team_abbreviationStringShort team abbreviation (e.g. 'LAS').
team_nameStringFull team display name (e.g. 'Las Vegas Aces').
teamsStringNested list of member-team membership spans.
seasonInt64Season year.
season_typeStringSeason type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats).
o_rapmFloat64Offensive regularized adjusted plus-minus per 100 possessions from the single-season ridge fit over possession-level lineup indicators, at the fixed NBA penalty described under rapm; positive means the player raised his team's scoring rate while on offense.
d_rapmFloat64Defensive regularized adjusted plus-minus per 100 possessions, negated from the raw points-allowed coefficient so a positive value marks a defender who suppresses opponent scoring; fit at the fixed NBA penalty described under rapm.
rapmFloat64Total regularized adjusted plus-minus per 100 possessions, exactly the sum of o_rapm and d_rapm. The ridge penalty is one fixed NBA value (2,683, sportsdataverse.nba.nba_rapm.RAPM_PENALTY) in every season and season type, so the scale compares across seasons (regular-season sd 1.53 to 1.99 per 100 over players with 400 possessions, 1997-2026; a shorter season, such as the 1999 lockout (1.53), shrinks harder, so part of a spread difference is sample size). Seasons published before November 2026 were fit at a per-season RidgeCV pick (1,931 or 5,179 in the regular season, up to 37,276 in the playoffs), and their spread jumps with it (sd 1.15 to 2.34): do not compare those values across seasons or with values fit at the fixed penalty.
off_possInt64Number of possessions the player was on the floor on offense, the count of design-matrix rows carrying his offensive indicator and therefore the offensive-side sample size behind o_rapm.
def_possInt64Number of possessions the player was on the floor on defense, the sample size behind d_rapm; it tracks off_poss almost exactly because substitutions rarely split an offense-defense pair.
o_adj_rapmFloat64Offensive prior-informed RAPM per 100 possessions: the ridge fit shrunk toward the player's box-score (SPM) prior. In releases fit with sportsdataverse-py #1137 or later it is relative to an average player, up to any offset the SPM prior carries (possession-weighted league mean near 0: 2025-26 +0.32). A player with no prior (a rookie, or no previous-season SPM) is shrunk toward 0 instead. Releases fit before #1137, whatever their build date, fit no intercept, so the league's points per possession leaked into every coefficient: o_adj_rapm averaged about +12.03 and d_adj_rapm -10.84 (2025-26), a thinly-used player kept less of that offset, and only their sum, adj_rapm, read on a common scale.
d_adj_rapmFloat64Defensive prior-informed RAPM per 100 possessions, positive for a defender who lowers opponent scoring. In releases fit with sportsdataverse-py #1137 or later it is relative to an average player, up to any offset the SPM prior carries (possession-weighted league mean near 0: 2025-26 +0.06). Releases fit before #1137, whatever their build date, averaged about -10.84 here (see o_adj_rapm).
adj_rapmFloat64Total prior-informed RAPM per 100 possessions, exactly the sum of o_adj_rapm and d_adj_rapm. Releases fit with sportsdataverse-py #1137 or later fit the ridge with an unpenalized intercept; releases fit before it (whatever their build date) fit none, which leaned this total toward heavy-minute players. Releases fit with #1150 or later also use one ridge penalty per league (NBA 3,728, WNBA 2,683) and the SPM prior doubled (nba_adj_rapm.ADJ_RAPM_PENALTY / ADJ_RAPM_PRIOR_SCALE); earlier ones took a per-season RidgeCV pick, whose spread collapsed in some seasons (WNBA 2004 sd 0.64 against plain RAPM's 1.47).
ospmFloat64Offensive statistical plus-minus per 100 possessions: the player's per-100 box-score feature vector scored through ridge coefficients trained on that season's o_rapm target.
dspmFloat64Defensive statistical plus-minus per 100 possessions from the same box-score feature vector scored through coefficients trained on the d_rapm target.
spmFloat64Total statistical plus-minus per 100 possessions, exactly the sum of ospm and dspm.
minFloat64Minutes played.
gpInt64Games played.
obpmFloat64Offensive box plus-minus per 100 possessions for this season and season type only, team-adjusted on its own so a team's minute-weighted obpm is its offensive rating minus the league's, divided by 5 (a traded player counted with his first team; league minute-weighted mean near 0). Releases fit before sportsdataverse-py #1148 put the whole team adjustment here (regular-season league minute-weighted mean about -2.9).
dbpmFloat64Defensive box plus-minus per 100 possessions for this season and season type only: bpm minus obpm, so a team's minute-weighted dbpm is (the league's offensive rating minus its defensive rating) / 5, positive for a good defense (league minute-weighted mean near 0). Releases fit before sportsdataverse-py #1148 left it unadjusted (regular-season league minute-weighted mean about +2.9, mostly positive).
bpmFloat64Box plus-minus (BPM 2.0) per 100 possessions for this season and season type only, not a career value: the box-score estimate of total impact. The team adjustment makes a team's minute-weighted bpm its net rating per 100 divided by 5 (the five %Min slots sum to the net rating; a traded player's minutes count with the first team he appears for in the logs). Releases fit before sportsdataverse-py #1148 targeted the full net rating, five times BPM 2.0's team mean.
warFloat64Wins above replacement, computed as (rapm minus a replacement level of -2.0 per 100) times total possessions divided by 100, divided by a points-per-win constant calibrated each season by regressing team wins on full-season point margin.
boban_filtered_skillFloat64BOBAN Kalman-filtered skill estimate at the end of the player's observed multi-season RAPM panel, i.e. his current-form rating after aging drift and possession-weighted observation noise.
boban_projected_ratingFloat64One-season-ahead BOBAN forecast, the filtered skill plus the empirical aging-curve drift at the player's last observed age; both season_type rows of a player-season carry the same value because the projection is not playoff-specific.
boban_projected_sdFloat64Standard deviation of the one-season-ahead BOBAN forecast, the square root of the filtered state variance plus the Kalman process variance; it sits at roughly 10.19 for a player with only one season in the panel, whose diffuse prior variance was never updated.
darko_filtered_skillFloat64Deprecated alias of boban_filtered_skill, kept for one release; use that column.
darko_projected_ratingFloat64Deprecated alias of boban_projected_rating, kept for one release; use that column.
darko_projected_sdFloat64Deprecated alias of boban_projected_sd, kept for one release; use that column.
o_rapm_nInt64Possessions o_rapm is measured over: off_poss, his offensive possessions. o_rapm_rank and o_rapm_pct are set only when it reaches the league's gate (1,700 NBA, 610 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
d_rapm_nInt64Possessions d_rapm is measured over: def_poss, his defensive possessions. d_rapm_rank and d_rapm_pct are set only when it reaches the league's gate (1,600 NBA, 1,200 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
rapm_nInt64Possessions rapm is measured over: off_poss + def_poss, his possessions at both ends. rapm_rank and rapm_pct are set only when it reaches the league's gate (3,100 NBA, 1,600 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
o_adj_rapm_nInt64Possessions o_adj_rapm is measured over: off_poss, his offensive possessions. o_adj_rapm_rank and o_adj_rapm_pct are set only when it reaches the league's gate (1,700 NBA, 610 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
d_adj_rapm_nInt64Possessions d_adj_rapm is measured over: def_poss, his defensive possessions. d_adj_rapm_rank and d_adj_rapm_pct are set only when it reaches the league's gate (1,600 NBA, 1,200 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
adj_rapm_nInt64Possessions adj_rapm is measured over: off_poss + def_poss, his possessions at both ends. adj_rapm_rank and adj_rapm_pct are set only when it reaches the league's gate (3,100 NBA, 1,600 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
ospm_nInt64Possessions ospm is measured over: off_poss, his offensive possessions. ospm_rank and ospm_pct are set only when it reaches the league's gate (1,700 NBA, 610 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
dspm_nInt64Possessions dspm is measured over: def_poss, his defensive possessions. dspm_rank and dspm_pct are set only when it reaches the league's gate (1,600 NBA, 1,200 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
spm_nInt64Possessions spm is measured over: off_poss + def_poss, his possessions at both ends. spm_rank and spm_pct are set only when it reaches the league's gate (3,100 NBA, 1,600 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
obpm_nInt64Possessions obpm is measured over: off_poss, his offensive possessions. obpm_rank and obpm_pct are set only when it reaches the league's gate (1,700 NBA, 610 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
dbpm_nInt64Possessions dbpm is measured over: def_poss, his defensive possessions. dbpm_rank and dbpm_pct are set only when it reaches the league's gate (1,600 NBA, 1,200 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
bpm_nInt64Possessions bpm is measured over: off_poss + def_poss, his possessions at both ends. bpm_rank and bpm_pct are set only when it reaches the league's gate (3,100 NBA, 1,600 WNBA), the sample at which a player's on-court rating of the same side is half signal (sportsdataverse._common.rate_gates.ON_OFF_MIN_N); a regularized or box rating is less noisy, so the gate is conservative.
war_nInt64Possessions behind war: off_poss + def_poss. war is a count, not a rate, so its rank has no sample gate.
boban_filtered_skill_nInt64Possessions behind boban_filtered_skill: off_poss + def_poss, this season's possessions at both ends. The boban filtered skill is a multi-season Kalman estimate with no single-side sample, so it takes the net on-court gate, the closest existing one: boban_filtered_skill_rank and boban_filtered_skill_pct are set only when this reaches the league's gate (3,100 NBA, 1,600 WNBA). Conservative, since the filter also carries earlier seasons.
boban_projected_rating_nInt64Possessions behind boban_projected_rating: off_poss + def_poss, this season's possessions at both ends. The boban next-season projection is a multi-season Kalman estimate with no single-side sample, so it takes the net on-court gate, the closest existing one: boban_projected_rating_rank and boban_projected_rating_pct are set only when this reaches the league's gate (3,100 NBA, 1,600 WNBA). Conservative, since the filter also carries earlier seasons.
boban_projected_sd_nInt64Possessions behind boban_projected_sd: off_poss + def_poss, this season's possessions at both ends. The boban projection's standard deviation is a multi-season Kalman estimate with no single-side sample, so it takes the net on-court gate, the closest existing one: boban_projected_sd_rank and boban_projected_sd_pct are set only when this reaches the league's gate (3,100 NBA, 1,600 WNBA). Conservative, since the filter also carries earlier seasons.
o_rapm_rankFloat64Rank of o_rapm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when o_rapm_n is under the league's gate (1,700 NBA, 610 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
d_rapm_rankFloat64Rank of d_rapm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when d_rapm_n is under the league's gate (1,600 NBA, 1,200 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
rapm_rankFloat64Rank of rapm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when rapm_n is under the league's gate (3,100 NBA, 1,600 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
o_adj_rapm_rankFloat64Rank of o_adj_rapm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when o_adj_rapm_n is under the league's gate (1,700 NBA, 610 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
d_adj_rapm_rankFloat64Rank of d_adj_rapm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when d_adj_rapm_n is under the league's gate (1,600 NBA, 1,200 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
adj_rapm_rankFloat64Rank of adj_rapm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when adj_rapm_n is under the league's gate (3,100 NBA, 1,600 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
ospm_rankFloat64Rank of ospm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when ospm_n is under the league's gate (1,700 NBA, 610 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
dspm_rankFloat64Rank of dspm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when dspm_n is under the league's gate (1,600 NBA, 1,200 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
spm_rankFloat64Rank of spm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when spm_n is under the league's gate (3,100 NBA, 1,600 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
obpm_rankFloat64Rank of obpm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when obpm_n is under the league's gate (1,700 NBA, 610 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
dbpm_rankFloat64Rank of dbpm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when dbpm_n is under the league's gate (1,600 NBA, 1,200 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
bpm_rankFloat64Rank of bpm among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when bpm_n is under the league's gate (3,100 NBA, 1,600 WNBA), and null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal. Regular-season gates: a playoff run rarely reaches one.
war_rankFloat64Rank of war among the season and season type's ranked players, 1 = best (higher is better), ties averaged; ungated (every player with a finite war qualifies), null when its season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value in the group is equal.
boban_filtered_skill_rankFloat64Rank of boban_filtered_skill among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when boban_filtered_skill_n is under the league's gate (3,100 NBA, 1,600 WNBA), when season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value is equal.
boban_projected_rating_rankFloat64Rank of boban_projected_rating among the season and season type's ranked players, 1 = best (higher is better), ties averaged; null when boban_projected_rating_n is under the league's gate (3,100 NBA, 1,600 WNBA), when season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value is equal.
boban_projected_sd_rankFloat64Rank of boban_projected_sd among the season and season type's ranked players, ASCENDING: 1 = the smallest sd, the most certain projection; ties averaged; null when boban_projected_sd_n is under the league's gate (3,100 NBA, 1,600 WNBA), when season or season_type is null, in a group of fewer than 10 ranked players, or when every ranked value is equal.
o_rapm_pctFloat64Percentile of o_rapm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
d_rapm_pctFloat64Percentile of d_rapm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
rapm_pctFloat64Percentile of rapm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
o_adj_rapm_pctFloat64Percentile of o_adj_rapm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
d_adj_rapm_pctFloat64Percentile of d_adj_rapm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
adj_rapm_pctFloat64Percentile of adj_rapm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
ospm_pctFloat64Percentile of ospm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
dspm_pctFloat64Percentile of dspm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
spm_pctFloat64Percentile of spm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
obpm_pctFloat64Percentile of obpm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
dbpm_pctFloat64Percentile of dbpm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
bpm_pctFloat64Percentile of bpm_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
war_pctFloat64Percentile of war_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
boban_filtered_skill_pctFloat64Percentile of boban_filtered_skill_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
boban_projected_rating_pctFloat64Percentile of boban_projected_rating_rank, 100 * (n + 1 - rank) / (n + 1) over the n ranked players of the season and season type; null where the rank is.
boban_projected_sd_pctFloat64Percentile of boban_projected_sd_rank, 100 * (n + 1 - rank) / (n + 1): high means a more certain projection (a smaller sd), not a larger one; null where the rank is.

Raises

ExceptionDescription
ValueErrorIf league_id is not "00" or "10".
KeyErrorIf a metric, season, season_type, off_poss or def_poss is missing.

Example

from sportsdataverse.nba import load_nba_player_impact, nba_player_impact_context
ranked = nba_player_impact_context(load_nba_player_impact(2026))
ranked.sort("adj_rapm_rank").select("player_name", "adj_rapm", "adj_rapm_rank", "adj_rapm_pct").head()

nba_player_impact_league_averages​

nba_player_impact_league_averages(impact: 'pl.DataFrame', *, league_id: 'str' = '00', return_as_pandas: 'bool' = False) -> 'pl.DataFrame | pd.DataFrame'

The league-average rows of a player_impact table, one block per season type.

The football F1 rows of ~sportsdataverse._common.league_context.league_averages over the players who pass each metric's sample gate, so n is that metric's qualified cohort: the players with a finite value and enough possessions. It is reported even where nba_player_impact_context leaves the ranks null (fewer than 10 qualifiers, or all equal). category is player_impact_ plus the season_type lowercased with spaces as underscores: player_impact_regular_season and player_impact_playoffs for the releases' two season types. qualifier_min is null (the gates differ by metric).

Parameters

ParameterTypeDefaultDescription
impactDataFrameA player_impact table, as nba_player_impact_context takes.
league_idstr'00'"00" NBA or "10" WNBA: the level label and the sample gates.
return_as_pandasboolFalseReturn a pandas.DataFrame instead of polars.

Returns

One row per (season, season type, metric) in ~sportsdataverse._common.league_context.LEAGUE_AVERAGES_SCHEMA; an empty input returns that schema with zero rows.

col_nametypedescription
seasonInt64Season of the league-average row, as the END year the player_impact table stamps (2026 = 2025-26).
levelStringPopulation the row describes: nba or wnba (the league_id passed).
entityStringKind of row summarized: always player for the impact table.
categoryStringTable and season type the row summarizes: player_impact_regular_season or player_impact_playoffs.
metricStringImpact metric the row summarizes, one of the 13 ranked columns (o_rapm through war).
meanFloat64Unweighted mean of the metric over the season type's ranked players, those whose _n reaches its sample gate.
medianFloat64Median of the metric over the same ranked players as mean.
sdFloat64Sample standard deviation (ddof 1) of the metric over the same ranked players; null with one player.
nInt64Number of ranked players with a finite value: the n of the _pct formula, not the possession count _n.
qualifier_minFloat64Always null here: each metric has its own possession gate rather than one table-wide threshold.

Raises

ExceptionDescription
ValueErrorIf league_id is not "00" or "10".
KeyErrorIf a metric, season, off_poss or def_poss is missing.

Example

from sportsdataverse.nba import load_nba_player_impact, nba_player_impact_league_averages
nba_player_impact_league_averages(load_nba_player_impact(2026))

nba_player_stats_advanced_context​

nba_player_stats_advanced_context(adv: 'pl.DataFrame', *, league_id: 'str' = '00', return_as_pandas: 'bool' = False) -> 'pl.DataFrame | pd.DataFrame'

Replace player_stats_advanced's API ranks of the rated measures with gated producer ranks.

For each measure of ADVANCED_RANKED, <m>_rank becomes the rank among the players of its (season, season_type, per_mode) whose poss reaches advanced_min_poss, and <m>_pct is appended (module docstring). A row's rank and percentile are null when it is under the gate, when its value is null or non-finite, when a group key is null, when fewer than ~sportsdataverse._common.league_context.MIN_COHORT_PLAYERS players qualify or every qualifying value is equal. Nothing is dropped, and running it on its own output gives the same frame.

Parameters

ParameterTypeDefaultDescription
advDataFrameA player_stats_advanced table (load_nba_stats_leaguedash("player_stats_advanced") / load_wnba_stats_leaguedash): season, season_type, per_mode, poss and the measures of ADVANCED_RANKED.
league_idstr'00'"00" NBA or "10" WNBA, which picks the gate.
return_as_pandasboolFalseReturn a pandas.DataFrame instead of polars.

Returns

adv with each ranked measure's <m>_rank replaced in place (Float64; ties share the average rank) and its <m>_pct (Float64) appended, in ADVANCED_RANKED order.

col_nametypedescription
player_idInt64Unique player identifier.
player_nameStringPlayer name.
nicknameStringTeam or athlete nickname.
team_idInt64Unique team identifier.
team_abbreviationStringShort team abbreviation (e.g. 'LAS').
ageFloat64Player age (in years).
gpInt64Games played.
wInt64Wins.
lInt64Losses.
w_pctFloat64Wins percentage (0-1 decimal).
minFloat64Minutes played.
e_off_ratingFloat64Estimated offensive rating: points produced per 100 possessions on the stats API's estimated-possession formula.
off_ratingFloat64Offensive rating: points scored per 100 possessions while the player is on the floor.
sp_work_off_ratingFloat64The stats API's SP_WORK copy of off_rating (the same measure under its alternate column set).
e_def_ratingFloat64Estimated defensive rating: points allowed per 100 possessions on the estimated-possession formula.
def_ratingFloat64Defensive rating: points allowed per 100 possessions while the player is on the floor.
sp_work_def_ratingFloat64The stats API's SP_WORK copy of def_rating (the same measure under its alternate column set).
e_net_ratingFloat64Estimated net rating: e_off_rating minus e_def_rating.
net_ratingFloat64Net rating (off rating - def rating).
sp_work_net_ratingFloat64The stats API's SP_WORK copy of net_rating (the same measure under its alternate column set).
ast_pctFloat64Assist percentage.
ast_toFloat64Assist-to-turnover ratio: assists divided by turnovers.
ast_ratioFloat64Assist ratio: assists per 100 possessions the player used, on the per-100 scale.
oreb_pctFloat64Offensive rebound percentage: share of available offensive rebounds the player grabbed while on the floor, as a decimal.
dreb_pctFloat64Defensive rebound percentage: share of available defensive rebounds the player grabbed while on the floor, as a decimal.
reb_pctFloat64Rebound percentage: share of all available rebounds the player grabbed while on the floor, as a decimal.
tm_tov_pctFloat64Turnover percentage: turnovers per 100 possessions the player used, on the per-100 scale (9.7 means 9.7 per 100, not 0.097).
e_tov_pctFloat64Estimated turnover percentage on the stats API's estimated-possession formula, on the per-100 scale like tm_tov_pct.
efg_pctFloat64Effective field-goal percentage, (fgm + 0.5 * fg3m) / fga, as a decimal.
ts_pctFloat64True shooting percentage (0-1).
usg_pctFloat64Usage percentage: share of the team's possessions the player used while on the floor, as a decimal (0.169 is 16.9%).
e_usg_pctFloat64Estimated usage percentage on the stats API's estimated-possession formula, as a decimal like usg_pct.
e_paceFloat64Estimated pace: possessions per regulation game on the estimated-possession formula.
paceFloat64Possessions per 48 minutes.
pace_per40Float64Pace per40.
sp_work_paceFloat64The stats API's SP_WORK copy of pace (the same measure under its alternate column set).
pieFloat64Player Impact Estimate (0-1).
possInt64Poss.
fgmInt64Field goals made.
fgaInt64Field goal attempts.
fgm_pgFloat64Field goals made per game.
fga_pgFloat64Field goals attempted per game.
fg_pctFloat64Field goal percentage (0-1).
gp_rankInt64The stats API's own rank of gp in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
w_rankInt64The stats API's own rank of w in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
l_rankInt64The stats API's own rank of l in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
w_pct_rankInt64The stats API's own rank of w_pct in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
min_rankInt64The stats API's own rank of min in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
e_off_rating_rankInt64The stats API's own rank of e_off_rating in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
off_rating_rankFloat64Producer rank of off_rating (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
sp_work_off_rating_rankInt64The stats API's own rank of sp_work_off_rating in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
e_def_rating_rankInt64The stats API's own rank of e_def_rating in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
def_rating_rankFloat64Producer rank of def_rating (lowest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
sp_work_def_rating_rankInt64The stats API's own rank of sp_work_def_rating in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
e_net_rating_rankInt64The stats API's own rank of e_net_rating in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
net_rating_rankFloat64Producer rank of net_rating (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
sp_work_net_rating_rankInt64The stats API's own rank of sp_work_net_rating in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
ast_pct_rankFloat64Producer rank of ast_pct (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
ast_to_rankFloat64Producer rank of ast_to (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
ast_ratio_rankInt64The stats API's own rank of ast_ratio in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
oreb_pct_rankFloat64Producer rank of oreb_pct (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
dreb_pct_rankFloat64Producer rank of dreb_pct (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
reb_pct_rankFloat64Producer rank of reb_pct (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
tm_tov_pct_rankFloat64Producer rank of tm_tov_pct (lowest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
e_tov_pct_rankInt64The stats API's own rank of e_tov_pct in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
efg_pct_rankFloat64Producer rank of efg_pct (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
ts_pct_rankFloat64Producer rank of ts_pct (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
usg_pct_rankFloat64Producer rank of usg_pct (heaviest usage first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
e_usg_pct_rankInt64The stats API's own rank of e_usg_pct in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
e_pace_rankInt64The stats API's own rank of e_pace in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
pace_rankInt64The stats API's own rank of pace in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
sp_work_pace_rankInt64The stats API's own rank of sp_work_pace in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
pie_rankFloat64Producer rank of pie (highest first) within season, season_type and per_mode, among players with poss of at least 1,550 (WNBA 800); null under the gate. Replaces the API's rank, which ranked every player.
fgm_rankInt64The stats API's own rank of fgm in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
fga_rankInt64The stats API's own rank of fga in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
fgm_pg_rankInt64The stats API's own rank of fgm_pg in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
fga_pg_rankInt64The stats API's own rank of fga_pg in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
fg_pct_rankInt64The stats API's own rank of fg_pct in the original stats API response (1 is the leader), kept as delivered: the function neither reranks it against the frame it is given nor gates it, unlike the producer ranks of the rated measures.
team_countInt64Number of teams the player's row covers (the stats API's TEAM_COUNT; more than 1 after a trade).
seasonInt64Season year.
league_idStringLeague identifier ('10' = WNBA).
season_typeStringSeason type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats).
per_modeStringThe stats API PerMode the row was requested with; the producer ranks are computed within each mode.
off_rating_pctFloat64Percentile of off_rating among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
def_rating_pctFloat64Percentile of def_rating among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
net_rating_pctFloat64Percentile of net_rating among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
ast_pct_pctFloat64Percentile of ast_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
ast_to_pctFloat64Percentile of ast_to among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
oreb_pct_pctFloat64Percentile of oreb_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
dreb_pct_pctFloat64Percentile of dreb_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
reb_pct_pctFloat64Percentile of reb_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
tm_tov_pct_pctFloat64Percentile of tm_tov_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
efg_pct_pctFloat64Percentile of efg_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
ts_pct_pctFloat64Percentile of ts_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
usg_pct_pctFloat64Percentile of usg_pct among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.
pie_pctFloat64Percentile of pie among the same ranked players: 100 * (n + 1 - rank) / (n + 1); null where the rank is.

Raises

ExceptionDescription
ValueErrorIf league_id is not "00" or "10".
KeyErrorIf a measure, season, season_type, per_mode or poss is missing.

Example

import polars as pl
from sportsdataverse.nba import load_nba_stats_leaguedash, nba_player_stats_advanced_context
adv = nba_player_stats_advanced_context(load_nba_stats_leaguedash("player_stats_advanced", seasons=2026))
adv.filter(pl.col("season_type") == "Regular Season").sort("ts_pct_rank").select(
"player_name", "poss", "ts_pct", "ts_pct_rank", "ts_pct_pct"
).head()

nba_predict_games​

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

Vectorized pregame predictions for a schedule of games.

Joins the ratings frame twice (home/away) and applies the closed-form predict_margin / win_prob_from_margin / predict_total math column-wise.

Parameters

ParameterTypeDefaultDescription
gamesDataFrameOne row per game with game_id, home_team_id, away_team_id and optionally neutral_site (missing column means every game is a true home game). Team-id dtypes must match ratings['team_id'] exactly.
ratingsDataFrameOne row per team with team_id, adj_off_rtg, adj_def_rtg, adj_net_rtg, adj_pace (the ~sportsdataverse.nba.nba_team_ratings.nba_team_ratings output for one season/as-of date).
league_idstr'00'"00"/"10"/"20".
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

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 raises a join-key dtype mismatch on a real schedule (the schedule's home_team_id is Int32, nba_team_ratings' team_id is String).

Raises

ExceptionDescription
ValueErrorIf a join-key dtype mismatches ratings['team_id'], or if ratings has duplicate team_id rows (e.g. multiple seasons passed at once).

Example

from sportsdataverse.nba.nba_game_predict import nba_predict_games
from sportsdataverse.nba.nba_team_ratings import nba_team_ratings
preds = nba_predict_games(games, nba_team_ratings(2024))

nba_reml_rapm​

nba_reml_rapm(possessions: 'pl.DataFrame', prior: 'dict[int, tuple[float, float]]', *, penalty: 'str' = 'fixed', lambdas: 'tuple[float, float] | None' = None, league_id: 'str | None' = None, return_as_pandas: 'bool' = False) -> 'pl.DataFrame | pd.DataFrame'

Season impact rating: RAPM shrunk toward a box prior, at a fixed league penalty or one chosen by REML.

The posterior mean of a prior-informed RAPM (the same design and sign convention as ~sportsdataverse.nba.nba_rapm.nba_rapm and ~sportsdataverse.nba.nba_adj_rapm.nba_adj_rapm). The prior is used as given (no scale multiplier). Two penalty rules:

  • penalty="fixed" (the default): the league's adjusted-RAPM penalty, ~sportsdataverse.nba.nba_adj_rapm.ADJ_RAPM_PENALTY (NBA 3,728), on offense and defense.
  • penalty="reml": one offense and one defense penalty chosen per call by restricted maximum likelihood (fit_reml_prior_ridge). REML's penalty is the ratio of the per-possession noise to how far players sit from their prior; with the v2 box prior it puts 90% of the weight on the prior on offense and 81% on defense (possession-weighted), and offense reaches the upper bound in 2018, 2019 and 2023.

Why fixed is the default: measured by tools/fit_box_prior_v2.py on NBA regular seasons 1998-2026 with the v2 box prior, against today's ~sportsdataverse.nba.nba_adj_rapm.nba_adj_rapm on the same held-out possessions, the fixed rule lowers the error by 1.64 bp of MSE (SE 0.10, better in all 29 seasons) and by 1.43 bp after a mid-season cut date (2006-2026, SE 0.29, 17 of 21); REML by 0.73 (SE 0.17, 22 of 29) and 1.03 (SE 0.49, 14 of 21). Head to head the fixed rule beats the REML pick by 0.91 bp on held-out games (SE 0.14, 27 of 29 seasons). The 3,728 was cross-validated on these seasons for the previous-season SPM prior, so refitting it for the v2 prior is open. The cut-date test counts 2006+ only (1998-2005 priors learn from later seasons); height and position come from one later index.

Built for the box prior of sportsdataverse.nba.nba_box_prior (o_prior / d_prior of ~sportsdataverse.nba.nba_box_prior.apply_box_prior), but any per-100 (o, d) prior works.

Parameters

ParameterTypeDefaultDescription
possessionsDataFrameA possession+lineup frame (points, off_player_1..5, def_player_1..5).
priordict[int, tuple[float, float]]{player_id: (o_prior, d_prior)} per 100 possessions (d positive = good defense). A player absent from it gets (0, 0): a league-average prior.
penaltystr'fixed'"fixed" (the league's adjusted-RAPM penalty) or "reml" (chosen per call).
lambdastuple[float, float] | NoneNone(lambda_o, lambda_d) to fit at; overrides penalty.
league_idstr | NoneNone"00", "10" or "20": the league whose fixed penalty is used. None reads it from the game_id prefix (NBA without one).
return_as_pandasboolFalseReturn a pandas.DataFrame instead of polars.

Returns

One row per player, columns REML_RAPM_SCHEMA: o_reml_rapm / d_reml_rapm / reml_rapm (per 100, d positive = good defense, reml_rapm = o + d), the prior used (o_box_prior / d_box_prior: whatever prior held, the box prior or another), the weight of a player's own prior in his posterior mean (o_prior_weight / d_prior_weight, 0 to 1; see RemlFit), possession counts, and the chosen penalties (lambda_o / lambda_d, the same on every row). Zero rows with that schema when no possession has a full lineup.

col_nametypedescription
player_idInt64NBA stats person id.
o_reml_rapmFloat64Offensive season impact per 100: the posterior mean of RAPM shrunk toward the prior at lambda_o (the league fixed penalty by default, REML with penalty="reml", or the lambdas= given).
d_reml_rapmFloat64Defensive season impact per 100 (positive = good defense) at lambda_d (the league fixed penalty by default, REML with penalty="reml", or the lambdas= given).
reml_rapmFloat64o_reml_rapm + d_reml_rapm.
o_box_priorFloat64The offensive prior the rating shrank toward (per 100; the box prior v2 when built by tools/fit_box_prior_v2.py).
d_box_priorFloat64The defensive prior the rating shrank toward (per 100, positive = good defense).
o_prior_weightFloat64Weight of the player's own offensive prior in his posterior mean, 0 to 1 (diagonal of M^-1 diag(lambda)).
d_prior_weightFloat64Weight of the player's own defensive prior in his posterior mean, 0 to 1.
off_possInt64Offensive possessions in the fit.
def_possInt64Defensive possessions in the fit.
lambda_oFloat64Offense penalty the fit used (points-per-possession scale; ADJ_RAPM_PENALTY by default, REML with penalty="reml", or the lambdas= given; the same on every row).
lambda_dFloat64Defense penalty the fit used (ADJ_RAPM_PENALTY by default, REML with penalty="reml", or the lambdas= given; the same on every row).

Raises

ExceptionDescription
ValueErrorIf penalty is not "fixed" or "reml".

Example

from sportsdataverse.nba import nba_reml_rapm
prior = {r["player_id"]: (r["o_prior"], r["d_prior"]) for r in priors.iter_rows(named=True)}
rating = nba_reml_rapm(possessions, prior) # fixed penalty
by_reml = nba_reml_rapm(possessions, prior, penalty="reml")
print(rating.sort("reml_rapm", descending=True).head())

nba_rookie_projection​

nba_rookie_projection(draft_year: "'int | list[int]'", *, league: 'str' = 'nba', pre_draft_features: 'bool' = False, college_prior: "'Optional[pl.DataFrame]'" = None, return_as_pandas: 'bool' = False) -> "'pl.DataFrame | pd.DataFrame'"

Project each pick's rookie and second-season value and rookie minutes from his pick.

Three pick curves (tools/models/nba_draft/fit_pick_curve.py, fit on draft classes 2003-2015) score the class sportsdataverse.nba.nba_draft_model.nba_draft_model returns:

  • proj_rookie_value: box value of the first NBA season the pick played (the corpus labels the first and second seasons played, so a pick stashed or injured in year one is labelled from his first season on the floor; proj_avail_pct is still for draft_year + 1).
  • proj_soph_value: box value of the second season played.
  • proj_rookie_min: minutes in the first season played.

Each curve ranks a class exactly as the pick does, so it ties the pick baseline by construction. On the 2016-2019 holdout Spearman is 0.477 for rookie value and the pick alike. proj_avail_pct comes from sportsdataverse.nba.nba_availability.nba_availability at the debut season. It is reported on its own and never multiplied into the value columns.

Parameters

ParameterTypeDefaultDescription
draft_yearint | list[int]A draft year or list of years.
leaguestr'nba'"nba" only; the WNBA has sportsdataverse.wnba.wnba_rookie_projection.wnba_rookie_projection.
pre_draft_featuresboolFalseAttach the pre-draft college and EuroLeague columns, as ~sportsdataverse.nba.nba_draft_model.nba_draft_model does. They are information only; no curve reads them.
college_priorOptional[DataFrame]NoneOptional frame keyed on player_id:Utf8, forwarded to ~sportsdataverse.nba.nba_draft_model.nba_draft_model as extra columns.
return_as_pandasboolFalseReturn a pandas DataFrame instead of polars.

Returns

One row per pick (1-60) of each class. |col_name |type | |:-----------------|:-------| |player_id |String | |draft_year |Int64 | |overall_pick |Int64 | |player_name |String | |proj_rookie_value |Float64 | |proj_soph_value |Float64 | |proj_rookie_min |Float64 | |proj_avail_pct |Float64 | |pro_tier |String | With pre_draft_features=True it adds the same college and EuroLeague columns as nba_draft_model. - proj_avail_pct falls back to 0.75 when availability has no row for the pick. - An empty or unpublished class returns the zero-row schema.

col_nametypedescription
player_idStringstats.nba.com person id of the pick (string).
draft_yearInt64Draft year (the June the class was picked).
overall_pickInt64Overall pick number, 1-60.
player_nameStringName of the pick as the draft history publishes it.
proj_rookie_valueFloat64Projected box value of the first NBA season the pick plays (not necessarily the season after the draft), from a pick curve fit on draft classes 2003-2015.
proj_soph_valueFloat64Projected box value of the second NBA season the pick plays, from a pick curve.
proj_rookie_minFloat64Projected minutes in the first NBA season the pick plays, from a pick curve (floored at 0).
proj_avail_pctFloat64Projected share of games available in the debut season, from nba_availability; 0.75 when it has no row for the pick. Never folded into the value columns.
pro_tierStringPick band: lottery (1-14), first_round (15-30) or second_round (31-60).

Raises

ExceptionDescription
ValueErrorleague is not "nba".
SeasonNotFoundErrorA draft year before 1996 (the draft release starts there).

Example

import polars as pl
from sportsdataverse.nba import nba_rookie_projection
board = nba_rookie_projection(2019)
print(board.sort("proj_rookie_value", descending=True).head())

# Pipeline next step (one line)

board.filter(pl.col("pro_tier") == "lottery")

nba_spm​

nba_spm(box_features: 'pl.DataFrame', coefficients: 'SpmCoefficients', *, return_as_pandas: 'bool' = False) -> 'Union[pl.DataFrame, pd.DataFrame]'

Apply fitted SPM coefficients to per-100 box features -> OSPM/DSPM/SPM.

Applies a linear scoring rule:

.. code-block:: text

ospm = X @ o_coef + o_intercept
dspm = X @ d_coef + d_intercept
spm = ospm + dspm

Parameters

ParameterTypeDefaultDescription
box_featuresDataFramePer-player per-100 features. Must contain player_id, every column in coefficients.feature_names, min, and gp.
coefficientsSpmCoefficientsA SpmCoefficients instance from train_spm.
return_as_pandasboolFalseWhen True, return a pandas.DataFrame instead of a polars.DataFrame.

Returns

Per-player frame with columns player_id (Int64), ospm (Float64), dspm (Float64), spm (Float64), min (Float64), gp (Int64).

col_nametypedescription
player_idInt64Unique player identifier.
ospmFloat64
dspmFloat64
spmFloat64
minFloat64Minutes played.
gpInt64Games played.

Example

from sportsdataverse.nba import nba_spm
ratings = nba_spm(box_feats, coef)
print(ratings.sort("spm", descending=True).head())

# Pipeline next step

ratings.filter(pl.col("min") >= 500).sort("spm", descending=True)

nba_team_ratings​

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

Opponent-adjusted team ratings (AdjOffRtg/AdjDefRtg/AdjNet/AdjPace), as-of-date aware.

Loads schedule + team box score for seasons, optionally filters to games strictly before as_of_date (the leakage boundary, via ~sportsdataverse.nba.nba_prediction_constants.as_of_ratings_split), computes per-game efficiency, runs the opponent-adjustment fixed points, and adds a per-season dense rank (on adj_net_rtg descending) and adj_net_z (z-score of adj_net_rtg).

Parameters

ParameterTypeDefaultDescription
seasonsUnion[int, list[int]]A season (e.g. 2024) or list of seasons.
league_idstr'00'"00" NBA / "10" WNBA / "20" G-League.
as_of_dateUnion[date, None]NoneIf given, only games with date < as_of_date are used (predictive/backtest usage); None computes full-season descriptive ratings.
return_as_pandasboolFalseReturn a pandas frame instead of polars.

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 year.
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).

Example

from sportsdataverse.nba.nba_team_ratings import nba_team_ratings
ratings = nba_team_ratings(2024)
ratings.sort("rank").head()

# As-of-date (leakage-safe) ratings for a backtest

import datetime as dt
ratings = nba_team_ratings(2024, as_of_date=dt.date(2024, 1, 15))

# WNBA / G-League via ``league_id``

wnba_ratings = nba_team_ratings(2024, league_id="10")