eduaguilera/whep

Energy extension warns many-to-many on every real build, drowning its real warnings

オープン

#647 opened on 2026/08/07

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)R (3 件のフォーク)auto 404
bugfootprint-extensiongood first issuehelp wantedmechanicalno-data-neededpriority:low

Repository metrics

Stars
 (1 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Found while measuring #553 (PR #645). Cosmetic but noisy, and it hides real join warnings.

What

.energy_allocate_to_sectors() in R/energy_co2_extension.R does

co2e |>
  dplyr::inner_join(.energy_sector_map(), by = "grp")

co2e has one row per (year, area_code, grp) and .energy_sector_map() has up to two rows per grp, so as soon as the input covers more than one country-year -- i.e. on every real build -- dplyr raises

Warning: Detected an unexpected many-to-many relationship between `x` and `y`.
i Row 1 of `x` matches multiple rows in `y`.
i Row 1 of `y` matches multiple rows in `x`.
i If a many-to-many relationship is expected, set `relationship = "many-to-many"` to silence this warning.

The relationship really is many-to-many and really is intended -- the join exists to fan each meat group out across its live-animal sectors -- so the warning is pure noise. It fires alongside the extension's genuine warnings (the unpriced-meat report, the missing-slaughter-share report), which is the actual cost: a caller reading warnings has to know which ones mean something.

Reproduce

Any multi-area input, e.g. tests/testthat/test_energy_co2_extension.R's own fixtures: 3 of the file's tests carry this warning today.

Fix

Add relationship = "many-to-many" to that one join, with a comment saying why (one group, several sectors, by design). One line, no numbers move -- dplyr's behaviour is identical, only the warning goes away. A test asserting the build raises no unexpected warning would keep it honest.

Not folded into PR #645 because that PR's diff is a modelling decision and this is unrelated tidying of a function #196/PR #283 last touched.

Refs #553.

コントリビューターガイド