Skip to content

Give gridded example cells their own country's area code - #773

Open
lbm364dl wants to merge 1 commit into
mainfrom
claude/gridded-fixture-wrong-country-686
Open

Give gridded example cells their own country's area code#773
lbm364dl wants to merge 1 commit into
mainfrom
claude/gridded-fixture-wrong-country-686

Conversation

@lbm364dl

Copy link
Copy Markdown
Collaborator

What was wrong (mechanism)

Five cells in the gridded example = TRUE fixtures in R/toy_examples.R carried an area_code that contradicts their own lon/lat. Unlike the cases #417 fixed, these are valid FAOSTAT codes, so they resolve — to the wrong country, silently, in the output a reader sees first:

export cell fixture area_code spatialize-country-grid says
read_luh2_landuse 9.25, 47.75 11 (Austria) 79 (Germany)
read_luh2_landuse 35.25, -1.25 79 (Germany) 114 (Kenya)
build_water_balance 9.25, 47.75 and 9.75, 47.75 11 (Austria) 79 (Germany)
build_water_balance 35.25, -1.25 and 35.75, -1.25 79 (Germany) 114 (Kenya)
get_soc_climate_drivers 9.25, 47.75 11 (Austria) 79 (Germany)

Verified against the deployed spatialize-country-grid pin (58,795 cells) — the majority cell-to-area assignment the real builders use. The sibling cells were already correct: Spain 203 (-3.25/-3.75, 40.25), Brazil 21 (-55.25/-55.75, -12.25), Greece 84 (26.25, 35.25), Argentina 9 (-64.25, -35.75).

Classification: mechanical. No published value changes — only documented example fixtures move, and only their area_code (plus the reporting-polity columns derived from it).

What changed

  • .example_water_balance(), .example_soc_climate_drivers() and .example_luh2_landuse() now carry the code the grid assigns to each cell (11 → 79, 79 → 114), with a comment at each fixture naming the source and the codes.
  • New checked-in extract tests/testthat/fixtures/country_grid_example_cells.csv: the pin's rows (revision 20260625T101041Z-8ff94) for exactly the 17 cells the example fixtures use. This is what makes the claim checkable offline — the suite must not read the pin.
  • New guard in tests/testthat/test_exported_polity_columns.R: sweeps every example = TRUE output that has lon, lat and area_code and requires the fixture code to equal the grid's. An empty area_code in the extract means the pin has no row for that cell — the deliberately abstract toy cells around (0.25, 0.25) and (0.25, 50.25) are open water, so they make no claim about a place and are left alone (the second half of the issue's decision). A cell that is not listed at all fails the guard, so a new fixture cell must be looked up against the pin rather than invented.

Not touched: the synthetic cell-polity crosswalks inside test_water_balance.R / test_luh2_landuse.R, which are injected inputs to wiring tests rather than claims a reader sees in exported output.

Verification

New guard against the unfixed fixtures (git stash push R/toy_examples.R):

Failure ('test_exported_polity_columns.R:287:3'): gridded example cells carry the grid's own area code
`disagree` (`actual`) and character() (`expected`) don't have the same values.
* Only in `actual`: "build_water_balance (9.25, 47.75): fixture 11, grid 79",
  "build_water_balance (9.75, 47.75): fixture 11, grid 79",
  "build_water_balance (35.75, -1.25): fixture 79, grid 114",
  "build_water_balance (35.25, -1.25): fixture 79, grid 114",
  "get_soc_climate_drivers (9.25, 47.75): fixture 11, grid 79",
  "read_luh2_landuse (35.25, -1.25): fixture 79, grid 114",
  "read_luh2_landuse (9.25, 47.75): fixture 11, grid 79"
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 51 ]

After the fix:

✔ |         52 | exported_polity_columns [6.2s]
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 52 ]

Affected consumers of the changed fixtures:

✔ |      1 101 | carbon_balance [9.1s]
✔ |          9 | exported_examples [1.3s]
✔ |         84 | luh2_landuse [37.9s]
✔ |         81 | toy_examples [2.4s]
✔ |      1 139 | water_balance [9.1s]
[ FAIL 0 | WARN 0 | SKIP 2 | PASS 414 ]

air format . run; lintr clean on both changed files. No roxygen changed, so man/ and _pkgdown.yml are untouched.

Closes #686.

🤖 Generated with Claude Code

Five cells in the gridded `example = TRUE` fixtures carried an `area_code`
that contradicted their own lon/lat. Unlike the cases whep#417 fixed these
codes are valid FAOSTAT codes, so they resolved -- to the wrong country,
silently, in the output a reader sees first: the cells at (9.25/9.75, 47.75)
in Baden-Wurttemberg were coded 11 (Austria) and the cells at
(35.25/35.75, -1.25) in the Kenyan Rift Valley were coded 79 (Germany), in
`.example_water_balance()`, `.example_soc_climate_drivers()` and
`.example_luh2_landuse()`. The `spatialize-country-grid` pin -- the majority
cell-to-area assignment the real builders use -- puts those cells in 79
(Germany) and 114 (Kenya), which is what the fixtures now say. The sibling
cells (Spain 203, Brazil 21, Greece 84, Argentina 9) were already right.

The whep#417 guard cannot see this class of defect, because a wrong-country
code resolves. Verifying a cell-to-country claim needs the pin, which the
offline suite must not read, so the pin's rows for exactly the cells the
example fixtures use are checked in as
tests/testthat/fixtures/country_grid_example_cells.csv, and a new guard in
test_exported_polity_columns.R sweeps every example output with lon/lat/
area_code against it. Cells the pin has no row for (the abstract toy cells
around (0.25, 0.25) and (0.25, 50.25), both open water) carry an empty
area_code in the extract and are left as deliberately synthetic; a fixture
cell that is not listed at all fails the guard, so a new cell has to be
looked up rather than invented.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lbm364dl lbm364dl self-assigned this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gridded example fixtures name the wrong country: cells in Kenya coded Germany, cells in Germany coded Austria

1 participant