Case Study 2 — Rosa's First Export: From a Messy App File to Clean Rounds (SIMULATED data)

Script: code/case_study_02.py. Data: SIMULATED. Rosa Delgado's representative 20-round sample (yardbook.cast, default seed 154023, golfkit.shotsim) on the demo member course (CR 70.8 / Slope 125, assumed values 🧪). The "export mess" is made by fixed rules in the script.

Setup

Rosa Delgado is a 15.4-handicap ER nurse in Phoenix (fictional, like the whole cast). She tracks her rounds with a shot-tracking app and practises putting more than anything else. In later chapters her data will show that approach play, not putting, is her biggest leak (Anchor A). But that story only works if her data are clean. Today she exports her last 20 rounds for the first time and hands the file to Coach Tasha Nguyen.

Tasha: Before we look at a single strokes-gained number, let's see what the file actually says. Rosa: It's straight from the app. It should be right. Tasha: The app's file is right about what the app recorded. Whether that's what you hit is a separate question.

The file has the problems every real export has: unfamiliar column names, the app's own vocabulary for lies, abbreviated units, and one hole typed in by hand after Rosa's phone battery died on the 12th tee of her seventh round.

The data

Here is the hole as it was actually played (the simulator's record, which is the truth in this exercise):

 round_id  hole  par  shot_no club start_lie  start_dist start_unit end_lie  end_dist end_unit  penalty  holed
        7    12    4        1    D       tee       367.1      yards fairway     157.6    yards        0  False
        7    12    4        2   7i   fairway       157.6      yards   rough      36.3    yards        0  False
        7    12    4        3   LW     rough        36.3      yards   green      21.3     feet        0  False
        7    12    4        4    P     green        21.3       feet   green       0.6     feet        0  False
        7    12    4        5    P     green         0.6       feet   holed       0.0     feet        0   True

A bogey 5. From memory, Rosa typed the 7-iron's start as 10 yards longer (rounded), logged the first putt's distance in yards, and forgot the tap-in.

The export itself:

Export written: rosa_export.csv, 1,834 rows, columns ['Round', 'Hole', 'Par', 'Shot', 'Club', 'Lie', 'Distance', 'start_unit', 'Result Lie', 'End Distance', 'end_unit', 'Penalty Strokes']
  rows with a Fringe lie: 75 finishes, 75 starts

Its quirks: "Round", "Shot", "Lie", "Distance" and "Result Lie" instead of the schema names; "Bunker" for sand; "Penalty" for a water finish; "Fringe" for 75 short fairway finishes (and the 75 shots that started there); units written "yd" and "ft"; "Driver" and "Putter" spelled out; and no holed column at all.

Analysis

Step 1 — Load: let the loader do the vocabulary

shots = rounds.load_shots_csv(path)          # names, lies, units and clubs normalised
rep = shots.attrs["validation"]              # the report is attached, not raised
print(rep.summary())

load_shots_csv maps the column names through its alias list ("Round" → round_id, "Lie" → start_lie, "Distance" → start_dist, "Penalty Strokes" → penalty), lower-cases the lies and maps the app's words ("bunker" → sand, "fringe" → fairway, "penalty" → water), expands the units ("yd" → yards, "ft" → feet), shortens the clubs ("DRIVER" → D, "PUTTER" → P) and rebuilds holed from end_lie == "holed". After loading, the lies are back in the book's vocabulary:

Lies after loading: {'green': 689, 'tee': 368, 'rough': 335, 'fairway': 312, 'recovery': 99, 'sand': 31}

What if your app uses a name the alias list doesn't know, say "Strokes From" for the start distance? Pass a mapping: rounds.load_shots_csv(path, column_map={"Strokes From": "start_dist"}). If a required column is still missing after mapping, the report's first line is a missing_columns error, and nothing downstream runs on a half-understood file. That is deliberate. A loader that guesses would happily treat a "carry" column as distance to the hole, and every strokes-gained number after that would be quietly wrong. Be explicit once, at the boundary, and everything inside the pipeline can trust the schema.

Treating the fringe as fairway is the same convention the simulator uses (it has no separate fringe lie). If your app distinguishes them and you want to keep the distinction, map "fringe" to a lie of your own and extend LIES. But then Broadie's baseline has no column for it, which is exactly why the book folds it into fairway.

Step 2 — Read the report

shots: 1,834 rows checked — 4 errors, 1 warnings
  error   bad_unit                     1
  error   chain_break                  2
  error   not_holed_out                1
  warning distance_increase            1
        check  round_id  hole  shot_no                                                            message
     bad_unit         7    12      4.0                                      putt distance must be in feet
not_holed_out         7    12      NaN                                         no holed shot on this hole
  chain_break         7    12      2.0 shot 1 ends fairway 157.6 yards; shot 2 starts fairway 168.0 yards
  chain_break         7    12      4.0        shot 3 ends green 21.3 feet; shot 4 starts green 21.3 yards

All four errors sit on the hand-typed hole, and each planted mistake is named. Every other hole passes every check, including the chain check across 75 fringe-to-fairway relabels, because the loader mapped both ends of each chain the same way. The single warning is a genuine simulated shot that finished farther from the hole than it started. It is legal, unusual, and present in the clean data too.

Tasha: Four errors, one hole. That's a good file. Now: do you remember that 7-iron? Rosa: It was from the 150 plate, a bit past it. And yes, I definitely tapped in.

Step 3 — Fix what you know, and only what you know

The fixes are deliberate and minimal:

  • The 7-iron starts where the drive finished (157.6 yards). The chain says so, and Rosa's memory of "a bit past the 150 plate" agrees.
  • The first putt's unit becomes feet.
  • The tap-in is added: from 0.6 feet on the green to holed.
After the fix:
shots: 1,835 rows checked — 0 errors, 1 warnings
  warning distance_increase            1

What if Rosa hadn't remembered? The honest options are to drop that hole from shot-level analysis (strokes gained, dispersion) and keep its score on the scorecard, or to keep it with the uncertain shot flagged. What you should never do is guess a distance to make the validator go quiet.

Step 4 — Does the cleaned file tell the truth?

Because this is simulated data, we can compare the cleaned file with the truth directly:

Round totals equal the truth in 20 of 20 rounds
GIR over 20 rounds: cleaned 91 vs truth 91; fairways hit: cleaned 144 vs truth 144

And here is the cost of not fixing it:

Unfixed file: round 7 total 95 vs truth 96

One forgotten tap-in makes one round a stroke better than it was. On its own that is tiny. But a forgotten tap-in is precisely the kind of error that repeats. A golfer who habitually skips logging tap-ins will under-count every round, overstate her putting and understate her handicap.

Step 5 — The handicap check

With clean scorecards we can compute the World Handicap System numbers (golfkit.whs: best 8 of the last 20 differentials, with no 0.96 multiplier):

Course Handicap at index 15.4: 16
Differentials (oldest first): [22.8, 25.5, 21.0, 15.5, 16.5, 21.9, 21.9, 19.2, 19.2, 25.5, 21.0, 20.1, 21.0, 15.5, 16.5, 25.5, 12.8, 9.2, 16.5, 16.5]
WHS index from these 20 (best 8 of 20, no 0.96): 14.9
Best eight: [9.2, 12.8, 15.5, 15.5, 16.5, 16.5, 16.5, 16.5] mean 14.88
Mean gross 93.4; mean differential 19.18

Figure CS2.1 — Rosa's differentials and the eight that set her index

📊 Figure (described): Twenty bars, one per round from oldest to newest, showing score differentials between 9.2 and 25.5. Eight bars are blue: rounds 4, 5, 14, 15, 17, 18, 19 and 20, the eight lowest. The other twelve are grey. A horizontal orange line at 14.9 marks the Handicap Index, the mean of the eight blue bars. Most grey bars sit between 19 and 26.

Two lessons hide here. First, the index from this 20-round sample is 14.9, not her nominal 15.4. That is entirely normal. The simulator calibrated her so that her expected index over many 20-round histories is 15.4, and any one history lands a few tenths away. Second, the mean differential (19.18) is more than four strokes above the index. That isn't a bug either. The index averages the best 8 of 20 rounds, so a typical round sits well above it. A golfer who "plays to her handicap" in an average round is playing better than usual. Chapter 29 develops both points.

What it means (and doesn't)

  • It means that most of an export's mess is vocabulary, and a loader can fix it mechanically and reliably. Here every hole but one came through clean.
  • It means the dangerous errors are the human ones, and they cluster: all four errors sat on the one hand-typed hole. The chain check found every one of them.
  • It means that cleaning should be checked against something. In this simulated case the check was the truth; with your own data it is the paper scorecard. Totals, GIR and fairway counts are cheap to compare.
  • It doesn't mean a clean validator report makes the data right. A consistently mis-measured distance (an app that mislocates the pin by 5 yards every time) passes every check. Validation catches inconsistency, not bias.
  • It means the order matters: validate first, then fix, then validate again, and only then compute. Every number in Step 5 was computed after the second clean report, never before the first.
  • It doesn't tell us anything about Rosa's real game yet. That starts in Chapter 10, against a named baseline.

Discussion questions

  1. Rosa's app records "Fringe". Argue for and against keeping it as a separate lie in your own yardbook.
  2. The validator treats a putt logged in yards as an error rather than silently converting it. Why is that the safer design?
  3. If Rosa routinely forgot tap-ins in 10% of holes, by roughly how much would her 20-round index be understated? (Think about which rounds enter the best eight.)
  4. Which of the three fixes in Step 3 depended on Rosa's memory, and which could the chain check alone justify?
  5. Tasha says "a good file". What would a bad file's report look like, and at what point would you refuse to analyse it?
  6. Rosa's twenty differentials take only ten distinct values (several appear two or three times). Explain why, using the differential formula and the fact that adjusted gross scores are whole numbers. Does that discreteness matter for the index?

Your turn

Export (or type) one of your own rounds into code/templates/shots_template.csv, run rounds.load_shots_csv, and fix what the report shows. Then compute the round total and putts with rounds.scorecard_from_shots and check them against your paper scorecard. If you don't track shots, do the same with scorecard_template.csv and rounds.load_rounds_csv for your last three rounds, and add each round's Score Differential using your course's real Course Rating and Slope.