Skip to main content

PWHL — additional Python functions — Analytics

pwhl_game_story​

pwhl_game_story(pbp: 'pl.DataFrame', schedule: 'pl.DataFrame', skater_box: 'pl.DataFrame', xg_shots: 'pl.DataFrame | None' = None, *, return_as_pandas: 'bool' = False) -> 'dict[str, pl.DataFrame] | dict[str, pd.DataFrame]'

How the winner won it, for one or many PWHL games: edges in goals, the moment, periods, runs, performers.

Parameters

ParameterTypeDefaultDescription
pbpDataFrameload_pwhl_pbp plays, one or many games, in the release's game order.
scheduleDataFrameload_pwhl_schedules rows: the home and away team ids and the official final.
skater_boxDataFrameload_pwhl_skater_boxscores rows (points, goals).
xg_shotsDataFrame | NoneNoneload_pwhl_xg_pbp rows; without them the xg and goaltending edges are left out.
return_as_pandasboolFalseReturn pandas frames instead of polars.

Returns

{"summary", "edges", "moment", "periods", "runs", "performers"}, the frames of ~sportsdataverse._common.game_story.GAME_STORY_SCHEMAS. The goals-by-situation edges add up to the margin exactly. The moment's rule is deciding_score (no PWHL in-game win probability). Rows of any frame without a game_id are dropped with a UserWarning.

summary:

col_nametypedescription
game_idInt64The game's HockeyTech (PWHL) game id.
home_team_idInt64Home team's HockeyTech (PWHL) team id.
away_team_idInt64Away team's HockeyTech (PWHL) team id.
home_scoreInt64Home team's official final score.
away_scoreInt64Away team's official final score.
winner_team_idInt64Winning team's id; null on a tie.
loser_team_idInt64Losing team's id; null on a tie.
marginInt64Winner's final score less the loser's; 0 on a tie.
decidedBooleanTrue when the game has a winner (false on a tie).
periods_agreeBooleanTrue when the period sums (from the play-by-play's running score) equal the official final; false flags a source whose plays end on another score.
n_periodsInt64Periods played, overtimes included.
overtimeBooleanTrue when the game went past regulation.

edges:

col_nametypedescription
game_idInt64The game's HockeyTech (PWHL) game id.
winner_team_idInt64Winning team's id (null on a tie, where the edges read from the home side's view).
loser_team_idInt64Losing team's id (null on a tie).
edgeStringEdge name. Accounting: even_strength_goals, power_play_goals, short_handed_goals, empty_net_goals, penalty_shot_goals, shootout; together the official margin exactly. Splits, with the xG shots: xg, goaltending (goals saved above expected).
kindStringaccounting for edges that split the game between them (their points_worth add up to the margin, exactly or nearly; see the function's docstring), split for overlapping cuts.
unitStringAlways goals: the scoring unit the edges are priced in.
winner_valueFloat64Winner's value for the edge in the edge's own unit: points for a points edge, a rate for a rate edge.
loser_valueFloat64Loser's value for the edge, in the same unit as winner_value.
points_worthFloat64The winner's edge in the sport's scoring unit: the winner's points from the edge less the loser's. Positive favours the winner.
rankInt64Rank of the edge within the game by points_worth, 1 = largest; equal worths keep the edge list's order.

moment:

col_nametypedescription
game_idInt64The game's HockeyTech (PWHL) game id.
play_idInt64The play's position in the release (null for a shootout's closing row).
orderInt64The play's position in the game's play order.
periodInt64Period of the play.
clockStringGame clock of the play as the source shows it.
team_idInt64Team of the play: the event's team (hockey), the batting team (baseball), the scoring team (soccer).
textStringPlay description as the source writes it.
wpaFloat64Home win probability after the play less before it.
winner_wpaFloat64The same change from the winner's side (null on a tie).
home_scoreInt64Home score after the play.
away_scoreInt64Away score after the play.
ruleStringAlways deciding_score: no in-game win-probability model ships for this league, so the moment is the winner's go-ahead-for-good score.

periods:

col_nametypedescription
game_idInt64The game's HockeyTech (PWHL) game id.
periodInt64Period number, from 1; overtimes follow regulation.
period_labelStringP1-P3, then OT, OT2, ... and SO for a shootout.
is_overtimeBooleanTrue for a period after regulation.
home_ptsInt64Home points in the period: its last running score less the previous period's.
away_ptsInt64Away points in the period.
home_cumInt64Home running score at the end of the period.
away_cumInt64Away running score at the end of the period.

runs:

col_nametypedescription
game_idInt64The game's HockeyTech (PWHL) game id.
team_idInt64Team that made the run.
pointsInt64The side's largest unanswered run: points it scored in a row with no score by the other side (a score correction stays in the run and counts against its side).
start_orderInt64Play order of the run's first score.
end_orderInt64Play order of the run's last score.
start_periodInt64Period of the run's first score.
end_periodInt64Period of the run's last score.
home_score_afterInt64Home score at the end of the run.
away_score_afterInt64Away score at the end of the run.

performers:

col_nametypedescription
game_idInt64The game's HockeyTech (PWHL) game id.
team_idInt64Team of the top performer.
player_idInt64The side's top performer's player id.
player_nameStringPlayer's display name.
metricStringAlways points: goals plus assists, the metric the performer is chosen by.
valueFloat64The player's points, goals plus assists (ties go to goals).

Example

import polars as pl
from sportsdataverse.pwhl import (
load_pwhl_pbp, load_pwhl_schedules, load_pwhl_skater_boxscores, load_pwhl_xg_pbp,
)
from sportsdataverse.pwhl.pwhl_game_story import pwhl_game_story
story = pwhl_game_story(
load_pwhl_pbp([2026]), load_pwhl_schedules([2026]), load_pwhl_skater_boxscores([2026]),
load_pwhl_xg_pbp([2026]),
)
story["edges"].filter(pl.col("rank") == 1)

# Every shootout

story["periods"].filter(pl.col("period_label") == "SO")

pwhl_game_total​

pwhl_game_total(games: 'Any', ratings: 'Any', *, league: 'str' = 'pwhl', **kwargs: 'Any') -> 'Any'

PWHL per-game expected total goals (re-export of the expected-goals helper).

Delegates to sportsdataverse.nhl.nhl_player_props.nhl_game_total with league="pwhl" defaulted.

Parameters

ParameterTypeDefaultDescription
gamesAnya schedule-shaped frame.
ratingsAnya pwhl_team_ratings-shaped frame.
leaguestr'pwhl'league key (defaults to "pwhl").

Returns

The NHL core's game_id/exp_total frame, computed with PWHL constants.

Example

from sportsdataverse.pwhl.pwhl_player_props import pwhl_game_total
totals = pwhl_game_total(games, ratings)

pwhl_in_game_win_prob​

pwhl_in_game_win_prob(pbp: 'Any', pregame_home_prob: 'float', *, league: 'str' = 'pwhl', **kwargs: 'Any') -> 'Any'

PWHL per-play live home win probability from the bundled in-game model.

Delegates to sportsdataverse.nhl.nhl_market.nhl_in_game_win_prob with league="pwhl" defaulted. NOTE: requires a committed pwhl_in_game_wp artifact, deferred until PWHL data lands (see module docstring); calling it before then raises a clear FileNotFoundError from the artifact loader, not a silent bad result.

Parameters

ParameterTypeDefaultDescription
pbpAnya play-by-play frame shaped like load_nhl_pbp_full.
pregame_home_probfloatthe pregame home win probability anchor.
leaguestr'pwhl'league key (defaults to "pwhl").

Returns

The NHL core's per-play home_win_prob frame.

Example

from sportsdataverse.pwhl.pwhl_market import pwhl_in_game_win_prob
wp = pwhl_in_game_win_prob(pbp, pregame_home_prob=0.5)

pwhl_player_props​

pwhl_player_props(seasons: 'Any', *, league: 'str' = 'pwhl', **kwargs: 'Any') -> 'Any'

PWHL empirical-Bayes shots/points player-prop projections.

Delegates to sportsdataverse.nhl.nhl_player_props.nhl_player_props with league="pwhl" defaulted and the PWHL box loader and ratings bound (see the module docstring).

Parameters

ParameterTypeDefaultDescription
seasonsAnyan int or iterable of seasons.
leaguestr'pwhl'league key (defaults to "pwhl").

Returns

The NHL core's per-(player, game, stat) projection frame.

Example

from sportsdataverse.pwhl.pwhl_player_props import pwhl_player_props
props = pwhl_player_props(2025)

pwhl_predict_games​

pwhl_predict_games(games: 'Any', ratings: 'Any', *, league: 'str' = 'pwhl', **kwargs: 'Any') -> 'Any'

PWHL vectorized pregame margin/win-prob/total (+ market edge).

Delegates to sportsdataverse.nhl.nhl_market.nhl_predict_games with league="pwhl" defaulted.

Parameters

ParameterTypeDefaultDescription
gamesAnya schedule-shaped frame (game_id, home_team, away_team, neutral_site).
ratingsAnya pwhl_team_ratings-shaped frame.
leaguestr'pwhl'league key (defaults to "pwhl").

Returns

The NHL core's per-game prediction frame, computed with PWHL constants.

Example

from sportsdataverse.pwhl.pwhl_market import pwhl_predict_games
preds = pwhl_predict_games(games, ratings)