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
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 edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.