Chapter 2 Notes — Cricket Data Sources

Chapter link: Chapter 2

Overview and learning objectives

Chapter 2 opens the table that every later chapter rests on. The hook is the first over of the IPL 2026 final: thirteen runs on television, nine rows in the data (six legal balls, three wides, one carrying a review). The chapter then covers where cricket data comes from, installing Python, the anatomy of a Cricsheet JSON file, a line-by-line reading of toolkit/cricdata.py (download, phases, parse_match, the Parquet cache, the canonical summaries), an eight-point data audit, the people register and name collisions, what Cricsheet cannot tell you, and a first analysis of the IPL 2026 and WPL 2026 leaders. The Crease module is data.py.

By the end of the chapter students should be able to:

  1. Distinguish a delivery from a legal delivery and compute runs conceded and economy for an over containing wides (the final's first over: 9 deliveries, 6 legal, 13 runs, economy 13.00).
  2. Explain the difference between ball_in_over and legal_ball_index and say which question each answers.
  3. Describe the JSON hierarchy (match → innings → over → delivery) and what parse_match() decides when flattening it.
  4. Run the eight-step audit checklist on a competition and report at least three findings.
  5. Use registry ids (batter_id, bowler_id) or only_player() to pin one person before aggregating across competitions.
  6. State what is withheld from the snapshot (Afghanistan men's internationals) and what Cricsheet never records.
  7. Use crease.data functions (load, filter_balls, season_table) to answer a one-line question.

Where students struggle

  • Counting rows as balls. The single most common error in the course. The hook exists to inoculate against it; revisit it whenever a strike rate looks wrong.
  • Strings that look like years. season == "2026" returns nothing for the BPL (labelled "2025/26") and IPL 2008 is "2007/08". Quiz question 20 is built on this.
  • Memory on small laptops. The men's Tests deliveries table is about 1,970 MB with all 42 columns but 240 MB with five. Students with 8 GB machines must learn columns= early.
  • Name collisions. "Rashid Khan" by name in men's T20Is is three different people (5 matches, 114 balls, 6 wickets). Across the 11 archives where the Afghan leg-spinner appears, name-grouping gives 396 matches / 9,079 balls / 504 wickets; pinned by id it is 392 matches, 8,989 balls, 500 wickets, economy 6.90 — and that is not his T20 career, because Afghanistan's internationals are withheld.
  • The 1-based over convention. Cricsheet numbers overs from zero; the toolkit adds 1. Students reading raw JSON alongside the parsed table get confused.
  • dropna() reflexes. Students drop rows with missing values without asking why they are missing (the NaN in legal_ball_index on wides is meaningful).
  • overs as a number. 32.5 overs is 197 balls, not 32.5 × 6.

Pacing

50-minute session. - 0–8: The nine-row hook; students count balls on paper (Productive Struggle). - 8–18: Sources, licence (ODC-By), why ball-by-ball changes everything. - 18–30: JSON anatomy and parse_match() decisions (legality, bowling team, non-boundary fours, first wicket only). - 30–40: The audit — miscounted overs, dismissal mix, extras through time. - 40–50: Names are not identities; the Rashid Khan demo.

75-minute session. Add a 15-minute live coding demo and a 10-minute walk through the IPL 2026 and WPL 2026 leaders. Lab time: a separate 60–90 minute lab for installation and building the cache. Parsing the Tests archive took 15.8 s on the book's machine and reading its Parquet 0.66 s; slower laptops may take several times longer the first time.

Lecture outline

  1. Nine rows for six balls (the IPL 2026 final's first over).
  2. Data sources: ball-by-ball files, statistics websites, tracking feeds, video; Cricsheet's licence and why you download rather than scrape.
  3. Toolkit setup: virtual environments; scripts versus notebooks.
  4. JSON anatomy: meta, info, innings → overs → deliveries; optional keys (IPL: extras on 5.487% of deliveries, wickets 4.972%, reviews 0.335%).
  5. cricdata.py line by line: download(), _phase(), parse_match(), build() and the atomic write-then-swap cache, load_*, batting_summary, bowling_summary.
  6. The audit: 295,732 JSON deliveries = 295,732 Parquet rows; 4 five-ball and 4 seven-ball IPL overs out of 45,276; 13 two-wicket deliveries in the whole snapshot; median legal balls per match (Test 1,949, ODI 557, T20I 231, Hundred 196).
  7. Dismissal mix across formats (lbw 16.6% of men's Test dismissals v 6.0% in the IPL; run-outs 2.6% v 8.1%; women's T20Is run-outs 14.2%).
  8. Names are not identities: 275 display names shared by 592 people; 70 names collide within single competitions.
  9. What Cricsheet cannot tell you.
  10. First analysis: IPL 2026 (Suryavanshi 776 runs, SR 237.31; Rabada 29 wickets, economy 9.68) and WPL 2026 (Mandhana top scorer with 377; Devine and NSS Sharma 17 wickets each).

Live coding demo

Script 1: code/02_parse_and_cache.py. Run it and show the first-over table. Ask students to predict len(over1) and over1["is_legal"].sum() before printing (9 and 6). Live change: compute "strike rate" for Sai Sudharsan in that over by dividing runs by rows and then by legal balls faced, and show the difference.

Script 2: code/05_people_register.py (about 20 seconds). Show the register entries for "Rashid Khan" (five people). Then show the name-grouped line (396 matches, 9,079 balls, 504 wickets, economy 6.93) against the only_player line (392, 8,989, 500, 6.90). Live change: replace the name with "Harmeet Singh" in the IPL — the chapter shows two bowler ids (27 matches/525 balls/26 wickets v 1 match/24 balls/1 wicket).

Script 3 (checkpoint): code/project_checkpoint.py prints the IPL season table (157.54 in 2012, 195.70 in 2026, 71 qualifying matches in 2026) and Kohli's IPL 2026 death overs: 66 off 27, 0 outs, SR 244.44. Ask: "Is 244.44 a fact about Kohli or about 27 balls?" — a bridge to Chapter 6.

In-class activity — "Audit a league"

Assign each group a competition (wpl, psl, bpl, t20s_female, hnd). Using the Chapter Summary's eight-step audit checklist, each group produces three findings in 20 minutes: one about season labels, one about results (ties, no-results, D/L), and one about over lengths or missing values. Groups working on hnd must discover the five-ball "overs" and mixed genders. Report back in one minute each; collect findings on a shared board.

Answers and teaching notes for key exercises

  • B1. 9 deliveries, 6 legal balls; 13 runs; all 13 charged to the bowler; economy 13.00.
  • B3. 8 / 45,276 ≈ 0.018% of overs miscounted; balls-remaining computed as 120 − 6 × overs is off by one after a seven-ball over. Pair with Wendell's "six pebbles" eye-test callout.
  • B4. Lbw share 2.8× higher in Tests; run-out share 3.1× higher in the IPL. Accept cricket explanations about defence on length versus risk-taking between the wickets.
  • B5. Suryavanshi 237.31, Gill 163.03; Gill used 122 more balls; at 9.91 runs per six balls those balls are worth ≈ 201.5 runs. Runs alone (776 v 732) hides the balls consumed — a preview of Chapters 8 and 13.
  • B6. Devine bowled 197 balls. Bell economy 5.53, strike rate 18.0; Devine 8.28 and 11.6. The choice depends on phase and on the price of a wicket; both samples are small.
  • D4. A good caveat paragraph names the withheld matches (Afghanistan's men's internationals), names the spinners most affected (e.g. Rashid Khan, whose figures here come only from franchise leagues), and proposes using franchise-league data with a cross-league adjustment (Chapter 26).

Assessment ideas

  • Audit report (graded): a one-page audit of any competition using the eight-step checklist, with code.
  • Short code task: "Produce Gujarat Titans' bowling figures from the 2026 final" (the second Try it). The key filter is innings 2; Rashid Khan 4-0-25-2, economy 6.25.
  • Concept quiz item: explain why batting_summary counts outs from player_out, not batter (non-striker run-outs).
  • Quiz question 20 (the empty BPL table) works as a debugging exam question.

Format, gender and region diversity notes

  • The WPL 2026 analysis (Mandhana 377 runs; Lauren Bell 12 wickets at economy 5.53 with 59.26% dots) is a full worked example, not a footnote.
  • Women's T20Is have the highest run-out share of any format in the dismissal table (14.2%); Exercise C5 tests the lazy "lower standard" explanation.
  • Case Study 2 is a Bangladesh v Pakistan Test at Mirpur (May 2026; Bangladesh won by 104 runs, Shanto 101 & 87) — Nusrat's home ground.
  • Be explicit about Afghanistan: Cricsheet withholds its men's internationals, so Afghan players appear only through franchise leagues. Students from Afghanistan or with an interest in its cricket deserve the honest explanation.
  • The Hundred (hnd) holds men's and women's matches in one archive with five-ball sets; filter by gender before any analysis.

Connections

  • Back to the argument it supports: Chapter 1.
  • pandas from the first line: Chapter 3.
  • Format baselines built on season_table: Chapter 5.
  • Shrinking Kohli's 66 off 27: Chapter 6.
  • Boundary-heavy profiles such as Suryavanshi's: Chapter 8.
  • What the missing tracking data would add: Chapter 15.
  • Following players across leagues by id: Chapter 26.
  • The reference appendix: Appendix B.