Five Countries Missing From the Average — Python Bug Hunt
Modelled on the Reinhart–Rogoff spreadsheet error. Their 2010 paper "Growth in a Time of Debt" was widely cited in austerity debates.
- Language: Python
- Layer: Backend
- Difficulty: Easy
- Concepts: Data, Off By One
- Modelled on: Reinhart–Rogoff · 2013
- Visible tests: every country is averaged; a header-only sheet has no average
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-RR2013
- Reported by: replication study
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- every country is averaged — illustrative figures, all seven rows: expected 1.86 but got 1.5
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Modelled on the Reinhart–Rogoff spreadsheet error. Their 2010 paper "Growth in a Time of Debt" was widely cited in austerity debates. In 2013 Thomas Herndon, Michael Ash and Robert Pollin re-ran the authors' own spreadsheet and found, among other issues, that an AVERAGE formula's cell range stopped short and left out five countries — Australia, Austria, Belgium, Canada and Denmark — from the headline growth figures. Reinhart and Rogoff acknowledged the coding error.
This reconstruction's summary.py averages a worksheet's growth column through a spreadsheet-style range helper, and the range it asks for starts several rows too late.
Fix average_growth so every country row is counted.
Bug report
BUG-RR2013 · Priority: High · Reported by: replication study
average_growth(rows) — rows[0] is the header, every later row is one country [name, bucket, growth]:
- average the growth column over EVERY country row (sheet row 2 through the last row)
- blank cells (None) are skipped, not counted as zero
- no values at all -> None
- round the result to 2 decimals
Observed: the first five countries in the sheet never reach the average, so the figure changes when the sheet is re-sorted.
Logs
[replicate] AVERAGE over L30:L44 — sheet data runs L30:L49
[replicate] 5 of 20 countries excluded from the 90%+ bucketThe code as shipped
src/sheet/summary.py (editable)
sheet = bug_require("./sheet.py")
GROWTH_COLUMN = 2
def average_growth(rows):
cells = sheet.cell_range(rows, 7, len(rows), GROWTH_COLUMN)
values = [c for c in cells if c is not None]
if not values:
return None
return round(sum(values) / len(values), 2)
Read-only context: src/sheet/sheet.py.
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.