Skip to content

Drop the inert gdp-population area relabelling - #771

Open
lbm364dl wants to merge 1 commit into
mainfrom
claude/canonicalise-gdp-pop-area-inert-721
Open

Drop the inert gdp-population area relabelling#771
lbm364dl wants to merge 1 commit into
mainfrom
claude/canonicalise-gdp-pop-area-inert-721

Conversation

@lbm364dl

Copy link
Copy Markdown
Collaborator

What was wrong

.canonicalise_gdp_pop_area() (R/build_cbs.R) relabelled the
gdp-population pin's area column into the polity-name vocabulary. Its
30-line comment and its two tests both said why:

.fill_with_proxies() joins population on c("year", "area") -- the name, not
a code -- and the two sides speak different vocabularies.

That stopped being true at commit 2210d05d. .fill_with_proxies() now does

pop_dt <- .proxy_bucket_key(gdp_pop, iso3_col = "area_code")
pop_dt <- pop_dt[, .(pop = sum(pop, na.rm = TRUE)), by = .(year, area_code)]
dt <- merge(dt, pop_dt, by = c("year", "area_code"), all.x = TRUE, sort = FALSE)

.proxy_bucket_key() keys on the ISO3 in area_code and the aggregation
reduces the pin to (year, area_code, pop), so the area label is dropped
before it reaches any join
. Verified .fill_with_proxies() is the only
consumer of .read_gdp_pop()'s output (gdp_pop flows
.read_cbs_inputs()inputs$gdp_pop.fill_historical_destinies()
.fill_with_proxies(), and nothing else reads it); get_population() in
R/population.R reads the pin directly via whep_read_file(), not through
.read_gdp_pop(). So the relabelling was inert with respect to every
published number, and the tests would have kept passing had the function been
identity().

What changed

Option 1 from the issue. Deleted the function, its stale 30-line comment
block, its two tests, and the two now-unused utils::globalVariables()
entries (canonical_area, key_row — grepped, used nowhere else).
.read_gdp_pop() now only renames Yearyear, with a short comment
recording why the label needs no canonicalisation and which commit made it
so.

Two tests replace the deleted pair:

  • .read_gdp_pop renames only the year column — mocks .read_input() with a
    four-row fixture and asserts the pin's area comes back untouched. This is
    the behaviour change, and it fails on the old code.
  • .fill_with_proxies ignores the population pin's area label — the guard
    that makes the removal safe: garbling the pin's area to
    "not a polity name" leaves both the filled food series and the joined
    pop identical. If a proxy is ever keyed on the name again, this fails
    loudly instead of the fill silently going unfilled.

No published value changes — the removed code only ever wrote a column
that was aggregated away. Classification: mechanical (dead-code removal
plus a false comment; no methodological choice).

Verification

Failing before the fix (source stashed, new tests in place):

── Failed tests ────────────────────────────────────────────────────────────────
Failure ('test_build_cbs.R:1216:3'): .read_gdp_pop renames only the year column
result$area (`actual`) not identical to pin$area (`expected`).

`actual`:   "Laos" "South Korea"       "Albania (1913-2025)" "Spain"
`expected`: "Lao"  "Republic of Korea" "Albania"             "Spain"

[ FAIL 1 | WARN 6 | SKIP 0 | PASS 148 ]

Passing after:

══ Results ═════════════════════════════════════════════════════════════════════
Duration: 3.3 s

[ FAIL 0 | WARN 6 | SKIP 0 | PASS 149 ]

(The 6 warnings are the pre-existing unfold_rest_of_world notices, unchanged
by this PR.) air format . made no further changes; lintr clean on all
three touched files (R/build_cbs.R, R/utils.R,
tests/testthat/test_build_cbs.R). No roxygen changed, so man/ and
_pkgdown.yml are untouched. Everything here is offline — no pin is read.

Closes #721.

🤖 Generated with Claude Code

`.canonicalise_gdp_pop_area()` existed to rewrite the `gdp-population`
pin's `area` labels into the polity-name vocabulary, because
`.fill_with_proxies()` joined population on `c("year", "area")` -- the
name, not a code.

Commit 2210d05 moved that join onto the reporting bucket:
`.fill_with_proxies()` now reduces the pin to `(year, area_code, pop)`
via `.proxy_bucket_key()`, which keys on the ISO3 in `area_code` and
aggregates away every other column. The `area` label is therefore
dropped before it reaches any join, and `.fill_with_proxies()` is this
input's only consumer -- `get_population()` reads the pin directly
through `whep_read_file()`, not through `.read_gdp_pop()`. So the
relabelling was inert with respect to every published number, while its
30-line comment and two tests still described and asserted a name-keyed
join that no longer exists.

Removed, together with its two tests and the two now-unused
`utils::globalVariables()` entries (`canonical_area`, `key_row`).
`.read_gdp_pop()` now only renames `Year` to `year`, and carries a short
comment saying why the label needs no canonicalisation.

Replaced by two tests: one pinning that `.read_gdp_pop()` hands the pin
over as published (it fails on the old code, which rewrote Lao -> Laos),
and one guard proving the label is inert -- garbling the pin's `area`
leaves `.fill_with_proxies()` output unchanged, so a future name-keyed
proxy fails loudly instead of silently going unfilled.

No published value changes: the removed relabelling only ever wrote a
column that was aggregated away.

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.

.canonicalise_gdp_pop_area() is now inert: its relabel is dropped before the proxy join, but its tests still assert it works

1 participant