Map fuel code 39 (electricity, any tariff) to standard electricity

modelling_e2e properties with main fuel 39 failed at the price boundary
(UnpricedFuelCode since #44fff767; previously mis-rated as non-electric →
the ~14-SAP over-rating flagged in earlier review).

Code 39 is SAP Table 12 "electricity, any tariff" (epc_codes.csv main_fuel 39 =
"electricity, unspecified tariff"; spec footnote (j): defines an electric system,
cost/CO2/PE = standard electricity). It was absent from API_FUEL_TO_TABLE_32, so
to_table_32_code(39) was None → is_electric_fuel_code(39) False and pricing
raised.

Fix: map API_FUEL_TO_TABLE_32[39] = 30 (standard electricity) — the canonical
place Khalim's fuel work added codes. One line makes classification, pricing,
CO2/PE and the billing carrier all agree (39 → 30 → ELECTRICITY).

Tests: to_table_32_code(39)==30, is_electric_fuel_code(39) True, price == standard
electricity, and the billing carrier resolves to ELECTRICITY. 0 corpus impact
(no lodged corpus cert uses 39); accuracy + mapper-corpus gates green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-06-24 11:20:32 +00:00
parent f7f74ea72b
commit 782c686969
3 changed files with 23 additions and 0 deletions

View file

@ -107,6 +107,12 @@ API_FUEL_TO_TABLE_32: Final[dict[int, int]] = {
10: 30, 11: 42, 12: 43, 13: 44, 14: 11, 15: 12, 16: 22, 17: 9,
18: 75, 19: 76, 20: 51, 21: 52, 22: 53, 23: 55, 24: 54, 25: 41,
26: 1, 27: 2, 28: 4, 29: 30, 30: 42, 31: 43, 32: 44, 33: 11,
# SAP Table 12 code 39 = "electricity, any tariff" (epc_codes.csv main_fuel
# 39 = "electricity, unspecified tariff"; spec footnote (j): defines an
# electric system, cost/CO2/PE = standard electricity). Resolve to standard
# electricity (30) so it classifies as electric and prices at the standard
# rate — otherwise it now raises UnpricedFuelCode (was: mis-rated non-electric).
39: 30,
}
# Gov-API `main_fuel_type` enum codes whose value COLLIDES with a

View file

@ -43,6 +43,7 @@ def test_table_32_codes_map_to_their_billing_fuel(code: int, fuel: Fuel) -> None
(0, Fuel.ELECTRICITY), # API "electricity" -> Table 32 code 30
(25, Fuel.HEAT_NETWORK), # API community heat -> Table 32 code 41
(14, Fuel.COAL), # API house coal -> Table 32 code 11
(39, Fuel.ELECTRICITY), # "electricity, any tariff" -> Table 32 code 30
],
)
def test_raw_api_fuel_codes_normalize_before_mapping(api_code: int, fuel: Fuel) -> None:

View file

@ -339,3 +339,19 @@ def test_additional_standing_charges_zero_for_oil_only() -> None:
# Assert
assert standing == 0.0
def test_electricity_any_tariff_code_39_resolves_to_standard_electricity() -> None:
# SAP Table 12 code 39 = "electricity, any tariff" (epc_codes.csv main_fuel 39
# = "electricity, unspecified tariff"; spec footnote (j): defines an electric
# system, cost = standard tariff). It must classify as electric and price at
# the standard-electricity rate — without the mapping it raises UnpricedFuelCode
# and is_electric_fuel_code(39) is False (mis-rated as non-electric).
from domain.sap10_calculator.tables.table_32 import (
is_electric_fuel_code,
to_table_32_code,
)
assert to_table_32_code(39) == 30
assert is_electric_fuel_code(39) is True
assert unit_price_p_per_kwh(39) == unit_price_p_per_kwh(30)