Give gridded example cells their own country's area code - #773
Open
lbm364dl wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong (mechanism)
Five cells in the gridded
example = TRUEfixtures inR/toy_examples.Rcarried anarea_codethat contradicts their ownlon/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:area_codespatialize-country-gridsaysread_luh2_landuseread_luh2_landusebuild_water_balancebuild_water_balanceget_soc_climate_driversVerified against the deployed
spatialize-country-gridpin (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.tests/testthat/fixtures/country_grid_example_cells.csv: the pin's rows (revision20260625T101041Z-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.tests/testthat/test_exported_polity_columns.R: sweeps everyexample = TRUEoutput that haslon,latandarea_codeand requires the fixture code to equal the grid's. An emptyarea_codein 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):After the fix:
Affected consumers of the changed fixtures:
air format .run;lintrclean on both changed files. No roxygen changed, soman/and_pkgdown.ymlare untouched.Closes #686.
🤖 Generated with Claude Code