Chapter 2 — Key Takeaways
Key Takeaways
- Ball-by-ball data is the raw material; scorecards are someone else's summary. Cricsheet's free files (ODC Attribution licence — credit the source) record every delivery, which lets you build any statistic, including ones nobody has invented yet.
- A Cricsheet match is a tree:
meta/info/innings→ overs → deliveries. The toolkit'sparse_match()flattens it to one row per delivery and never drops or merges an event. - Every definition lives in one file.
toolkit/cricdata.pydecides what a ball, a run, an out and a wicket are. You have read it; when a later chapter quotes a number, you know how it was counted. - Parse once, read many times. The Parquet cache made loads 10–24× faster in our timing, and it is written to a temp file and swapped in, so no reader ever sees a half-written cache. Read only the columns you need: the Tests table is about 2 GB in memory in full, 240 MB with five columns.
- Audit before you analyse. Season labels are strings ("2007/08" is IPL 2008); ties have no
winner; umpires miscount overs; 5 of 3,341 Test innings carry innings-level penalty runs that no delivery records. - Know what's missing. Cricsheet withholds Afghanistan men's internationals (14 Tests, 162 ODIs, 166 T20Is, 10 non-official T20s in this snapshot) and records no line, length, speed, shot direction, fielding position or dropped catch.
- Names are not identities. 70 names collide within single competitions; men's T20Is have three
different "Rashid Khan"s. Every delivery carries registry ids (
batter_id,bowler_id,non_striker_id,player_out_id): group by them, or pin a player withonly_player(). - The format shows in the data itself. A median Test has 1,949 legal balls, a T20I 231; lbw is 16.6% of Test dismissals and 6.0% in the IPL. Never pool formats.
- Even a first leaderboard misleads. IPL 2026's top three run-scorers were within 54 runs of each other but used between 327 and 457 balls.
Metrics & Formulas
| Term | Definition (as the toolkit counts it) | Watch out for |
|---|---|---|
| Legal delivery | Not a wide and not a no-ball | Byes and leg-byes are legal |
| Balls faced | Deliveries as striker, excluding wides (no-balls count) | Rows ≠ balls |
| Runs (batting) | Runs off the bat | Extras are not the batter's |
| Outs | Dismissals by player_out, excluding retired hurt / not out |
Non-striker run-outs count |
| Innings | Distinct (match, innings) as striker or non-striker | Players with zero balls faced get no row |
| Batting average | runs / outs | Undefined (NaN) with zero outs |
| Strike rate | 100 × runs / balls faced | — |
| Runs conceded | total − byes − leg-byes − penalty | Wides and no-balls are charged |
| Bowler wickets | bowled, caught, c&b, lbw, stumped, hit wicket | Run-outs excluded |
| Economy | 6 × runs conceded / legal balls | Never use the overs label |
overs (label) |
balls // 6 + (balls % 6) / 10 | 4.3 = 27 balls, not 25.8 |
| T20 phases | 1–6 / 7–15 / 16–20 (1-based overs) | Cricsheet overs are 0-based |
| ODI phases | 1–10 / 11–40 / 41–50 | — |
| Hundred phases | balls 1–25 / 26–75 / 76–100 | "Overs" are 5-ball sets |
| Test phases | none | Use innings, overs into innings, ball age |
Common Mistakes (and the fix)
| Mistake | Fix |
|---|---|
| Counting rows as balls | Count is_legal, or use legal_ball_index |
Filtering season == "2008" for IPL 2008 |
Use the label "2007/08", or add an integer year |
| Inferring balls remaining from over numbers | Count legal balls — overs of 5 and 7 legal balls exist |
Summing is_wicket for a bowler |
Use bowler_wicket() — run-outs aren't the bowler's |
dropna() on the matches table |
Ask why each value is missing; most are structural |
| Grouping by name across leagues | Group by the _id columns, or use only_player(balls, name) |
| Loading all 42 columns of the Tests table | pd.read_parquet(path, columns=[...]) |
| Trusting a stale cache | download(code, force=True) and build(code, force=True) |
| Pooling formats or genders | Filter on match_type/competition and gender first |
Decision Framework — before you trust a number
- Which competition, format and gender? Is The Hundred filtered by gender? Are formats separate?
- Which season? Did you check the label, not assume the year?
- Which matches? Ties, no-results, D/L, super overs — included or excluded, and said so?
- Which definition? Balls faced, outs, runs conceded — the toolkit's, or your own?
- Which people? Could a name be two players?
- What's missing? Withheld matches; coverage start dates; no tracking data.
- Does it add up? Runs off the bat + extras = total; your totals match the published result.