diff --git a/pipeline/stage_uk_ab2026_expected.json b/pipeline/stage_uk_ab2026_expected.json index e1f229e17..305628c31 100644 --- a/pipeline/stage_uk_ab2026_expected.json +++ b/pipeline/stage_uk_ab2026_expected.json @@ -10,35 +10,35 @@ } }, "ab2026__electricity_vat_zero_rate_to_july_2027": { - "claims": 74, + "claims": 69, "computed": 4, "reasons": { "cumulative_real_terms": 1, - "exchequer_component": 14, + "exchequer_component": 12, "household_count": 1, - "typical_bill": 8, + "typical_bill": 5, "vigintile_ahc_breakdown": 38, "zero_both_sides": 8 } }, "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred": { - "claims": 28, + "claims": 27, "computed": 0, "reasons": { "cumulative_real_terms": 1, "fuel_duty_base": 6, - "motorists_count": 2, + "motorists_count": 1, "vigintile_ahc_breakdown": 19 } }, "ab2026__household_energy_payment_100_bands_a_to_d": { - "claims": 60, + "claims": 51, "computed": 0, "reasons": { - "devolved_share_not_modelled": 24, + "devolved_share_not_modelled": 18, "england_only_average": 1, - "household_count": 2, - "share_of_households": 14, + "household_count": 1, + "share_of_households": 12, "vigintile_ahc_breakdown": 19 } }, @@ -48,7 +48,7 @@ "reasons": {} }, "ab2026__pension_tax_allowance": { - "claims": 89, + "claims": 88, "computed": 7, "reasons": { "cumulative_real_terms": 1, @@ -57,7 +57,7 @@ "no_fiscal_year": 1, "taken_out_of_tax_count": 1, "vigintile_ahc_breakdown": 19, - "worked_example": 6, + "worked_example": 5, "zero_both_sides": 2 } }, @@ -79,7 +79,7 @@ } } }, - "claims": 368, + "claims": 352, "computed": 35, "pairing": { "046a69003c7b96e95efe": { @@ -367,19 +367,19 @@ "reasons": { "benefit_recipients_count": 1, "cumulative_real_terms": 4, - "devolved_share_not_modelled": 24, + "devolved_share_not_modelled": 18, "england_only_average": 1, - "exchequer_component": 141, + "exchequer_component": 139, "fuel_duty_base": 6, - "household_count": 3, + "household_count": 2, "measure_ended": 4, - "motorists_count": 2, + "motorists_count": 1, "no_fiscal_year": 1, - "share_of_households": 14, + "share_of_households": 12, "taken_out_of_tax_count": 1, - "typical_bill": 8, + "typical_bill": 5, "vigintile_ahc_breakdown": 95, - "worked_example": 6, + "worked_example": 5, "zero_both_sides": 22 } } diff --git a/results/uk/ab2026/STAGING_TALLY.json b/results/uk/ab2026/STAGING_TALLY.json index ce093417f..33a272316 100644 --- a/results/uk/ab2026/STAGING_TALLY.json +++ b/results/uk/ab2026/STAGING_TALLY.json @@ -10,35 +10,35 @@ } }, "ab2026__electricity_vat_zero_rate_to_july_2027": { - "claims": 74, + "claims": 69, "computed": 4, "reasons": { "cumulative_real_terms": 1, - "exchequer_component": 14, + "exchequer_component": 12, "household_count": 1, - "typical_bill": 8, + "typical_bill": 5, "vigintile_ahc_breakdown": 38, "zero_both_sides": 8 } }, "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred": { - "claims": 28, + "claims": 27, "computed": 0, "reasons": { "cumulative_real_terms": 1, "fuel_duty_base": 6, - "motorists_count": 2, + "motorists_count": 1, "vigintile_ahc_breakdown": 19 } }, "ab2026__household_energy_payment_100_bands_a_to_d": { - "claims": 60, + "claims": 51, "computed": 0, "reasons": { - "devolved_share_not_modelled": 24, + "devolved_share_not_modelled": 18, "england_only_average": 1, - "household_count": 2, - "share_of_households": 14, + "household_count": 1, + "share_of_households": 12, "vigintile_ahc_breakdown": 19 } }, @@ -48,7 +48,7 @@ "reasons": {} }, "ab2026__pension_tax_allowance": { - "claims": 89, + "claims": 88, "computed": 7, "reasons": { "cumulative_real_terms": 1, @@ -57,7 +57,7 @@ "no_fiscal_year": 1, "taken_out_of_tax_count": 1, "vigintile_ahc_breakdown": 19, - "worked_example": 6, + "worked_example": 5, "zero_both_sides": 2 } }, @@ -79,24 +79,24 @@ } } }, - "claims": 368, + "claims": 352, "computed": 35, "reasons": { "benefit_recipients_count": 1, "cumulative_real_terms": 4, - "devolved_share_not_modelled": 24, + "devolved_share_not_modelled": 18, "england_only_average": 1, - "exchequer_component": 141, + "exchequer_component": 139, "fuel_duty_base": 6, - "household_count": 3, + "household_count": 2, "measure_ended": 4, - "motorists_count": 2, + "motorists_count": 1, "no_fiscal_year": 1, - "share_of_households": 14, + "share_of_households": 12, "taken_out_of_tax_count": 1, - "typical_bill": 8, + "typical_bill": 5, "vigintile_ahc_breakdown": 95, - "worked_example": 6, + "worked_example": 5, "zero_both_sides": 22 } } diff --git a/results/uk/ab2026/STAGING_UNANSWERED.jsonl b/results/uk/ab2026/STAGING_UNANSWERED.jsonl index fb6898687..5e19becc4 100644 --- a/results/uk/ab2026/STAGING_UNANSWERED.jsonl +++ b/results/uk/ab2026/STAGING_UNANSWERED.jsonl @@ -20,7 +20,6 @@ {"claim_id": "da28c482b7b21e2458e0", "fy": "2028-29", "measure_key": "ab2026__carers_allowance_earnings_taper", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} {"claim_id": "f0a07cdf34809219807c", "fy": "2026-27", "measure_key": "ab2026__carers_allowance_earnings_taper", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} {"claim_id": "0b9e830f9f2148a86903", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} -{"claim_id": "0eb3a5872cdd92efd62b", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "energy_bill_change", "reason": "typical_bill", "source": "hm_treasury"} {"claim_id": "13cf3e7771338e1f4e5d", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "1adfaea47df3d0341c00", "fy": "2031-32", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "cumulative_real_terms", "source": "tax_policy_associates"} {"claim_id": "1fbb6781190ec8c68101", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} @@ -31,10 +30,8 @@ {"claim_id": "2ad78847dcd6a66e48da", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "2c2d556673325dd10db1", "fy": "2027-28", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "energy_bill_change", "reason": "typical_bill", "source": "resolution_foundation"} {"claim_id": "2ea2a7570a9ab752ebe1", "fy": "2030-31", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} -{"claim_id": "3278a981efdf67a241d8", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "energy_bill_change", "reason": "typical_bill", "source": "hm_treasury"} {"claim_id": "33033ee668360ddec3a1", "fy": "2029-30", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "zero_both_sides", "source": "hm_treasury"} {"claim_id": "35a84e0b0840d9035c34", "fy": "2029-30", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} -{"claim_id": "3649310358514ba69178", "fy": "2026-27", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} {"claim_id": "3bd173c4baddaf2bf1dc", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "3e46d6a193d5c74a1680", "fy": "2031-32", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "zero_both_sides", "source": "obr_efo"} {"claim_id": "3fd1c92e7173b973019d", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} @@ -80,9 +77,7 @@ {"claim_id": "dbe9f8a5aa4473de9b19", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "e190f813261cbdd81888", "fy": "2028-29", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "zero_both_sides", "source": "hm_treasury"} {"claim_id": "e4f61db7a499cb41e808", "fy": "2026-27", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} -{"claim_id": "e52aab9941b88637887f", "fy": "2027-28", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} {"claim_id": "e57a170c745060501138", "fy": "2031-32", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} -{"claim_id": "eaf846087b8d6ddea178", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "energy_bill_change", "reason": "typical_bill", "source": "hm_treasury"} {"claim_id": "f3fd1a1088ca70b70241", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "fa3bcc3f88d22c49416e", "fy": null, "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "energy_bill_change", "reason": "typical_bill", "source": "resolution_foundation"} {"claim_id": "fd5134601b847e7f15d3", "fy": "2027-28", "measure_key": "ab2026__electricity_vat_zero_rate_to_july_2027", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} @@ -111,7 +106,6 @@ {"claim_id": "cd6b695cab3a4bd785f1", "fy": "2030-31", "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "revenue_change", "reason": "fuel_duty_base", "source": "hm_treasury"} {"claim_id": "d1153a1337ae90c200be", "fy": null, "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "d73ddcb30383f13b79b8", "fy": "2027-28", "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "revenue_change", "reason": "fuel_duty_base", "source": "hm_treasury"} -{"claim_id": "d7c3812e6f3553403dfc", "fy": null, "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "affected_count", "reason": "motorists_count", "source": "hm_treasury"} {"claim_id": "df109dbab38edee8ea8c", "fy": null, "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "e15c13c4a97fd02ea5e9", "fy": null, "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "e16251def4cd0865a23d", "fy": null, "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} @@ -119,17 +113,14 @@ {"claim_id": "f2c1b47f67dfb730ccc5", "fy": "2029-30", "measure_key": "ab2026__fuel_duty_5p_cut_extended_and_rpi_rise_deferred", "metric": "revenue_change", "reason": "fuel_duty_base", "source": "hm_treasury"} {"claim_id": "00676b8d6f278ac6eb80", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "022a08d43b8b7ffe678f", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} -{"claim_id": "02ab244ec5dc7ee9e970", "fy": "2028-29", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "0445a014fe96e744623f", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "08b478f5153683c3be20", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "resolution_foundation"} -{"claim_id": "0cfd4c77c0cd21ea395c", "fy": "2029-30", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "0d191361e56571000fd8", "fy": "2029-30", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "1426a63159f6324492d7", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "14b0008d5789757702d9", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "179a12e4c99fc9475011", "fy": "2028-29", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "hm_treasury"} {"claim_id": "227ef9ad235e84c803a4", "fy": "2030-31", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "2851ef42d7e9ce079ad8", "fy": "2031-32", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} -{"claim_id": "3e64d594a3c609717593", "fy": "2030-31", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "45acc443c692b9d07568", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "4e883cfdd74a27f2980c", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "eligibility_rate", "reason": "share_of_households", "source": "resolution_foundation"} {"claim_id": "51f8f6c066df275a5592", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} @@ -140,27 +131,22 @@ {"claim_id": "61e86c3e573ec9f44acd", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "ifs"} {"claim_id": "61faee9f46653d821b59", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "631957af42975c560dbf", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "ifs"} -{"claim_id": "6560f6805d6d34cabc30", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "68b91da5ca82da475dfb", "fy": "2031-32", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "hm_treasury"} {"claim_id": "6b831a178a6c536be439", "fy": "2028-29", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "703b9028d019fd496fca", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "736158354806fd17e7b5", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "resolution_foundation"} {"claim_id": "75781db5ab78cc65048e", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} -{"claim_id": "7ac037a6e12fed42c70a", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "resolution_foundation"} {"claim_id": "82d8c7188f76cf70e29f", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "hm_treasury"} {"claim_id": "85a98bac804c8bfdc3b3", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "england_only_average", "source": "ifs"} {"claim_id": "8bab4d779073e7e0d20b", "fy": "2028-29", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} -{"claim_id": "8cd2f21ab19f781a04b6", "fy": "2027-28", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "944ed860d0907b92ddd4", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "9b9a1b88df02c09f81f1", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "hm_treasury"} {"claim_id": "9bcdd43e7a5c52897392", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "resolution_foundation"} {"claim_id": "a50960ee228ec33f1a07", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "a6053f19a370a6698068", "fy": "2031-32", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "a775d0abe2c157e4aedd", "fy": "2029-30", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "hm_treasury"} -{"claim_id": "aab288b06e71d09d1f51", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "ifs"} {"claim_id": "b03186a5b6ea3f5a8d19", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "b0b77242694722166cb6", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} -{"claim_id": "c3079f9d4b23100984df", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_count", "reason": "household_count", "source": "hm_treasury"} {"claim_id": "c8e36ca4e979fa36f564", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "c95fd9ef5ed55064a53a", "fy": "2030-31", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "hm_treasury"} {"claim_id": "d10ab61af1a075f990e6", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} @@ -169,7 +155,6 @@ {"claim_id": "d7e26e8076c2412533ba", "fy": "2027-28", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "d8dae396eb1d0904f52d", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "defc914d261d3cd647d1", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "eligibility_rate", "reason": "share_of_households", "source": "resolution_foundation"} -{"claim_id": "e99bea5be0226ef87213", "fy": "2031-32", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} {"claim_id": "effcd51319e9d80399da", "fy": "2026-27", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "eligibility_rate", "reason": "share_of_households", "source": "resolution_foundation"} {"claim_id": "f33cfa8d1d6fa09fdea8", "fy": null, "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "affected_share", "reason": "share_of_households", "source": "ifs"} {"claim_id": "f484953007af7dfd7d0f", "fy": "2029-30", "measure_key": "ab2026__household_energy_payment_100_bands_a_to_d", "metric": "revenue_change", "reason": "devolved_share_not_modelled", "source": "obr_efo"} @@ -208,7 +193,6 @@ {"claim_id": "44303c30d63361eae120", "fy": "2029-30", "measure_key": "ab2026__pension_tax_allowance", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} {"claim_id": "44d20f23db01fe9677d0", "fy": "2029-30", "measure_key": "ab2026__pension_tax_allowance", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} {"claim_id": "46b6cc2cedabc2516764", "fy": "2027-28", "measure_key": "ab2026__pension_tax_allowance", "metric": "tax_liability", "reason": "worked_example", "source": "hm_treasury"} -{"claim_id": "4b3185f467f7d123b383", "fy": "2027-28", "measure_key": "ab2026__pension_tax_allowance", "metric": "tax_liability", "reason": "worked_example", "source": "hm_treasury"} {"claim_id": "4bf4c0f394e8c9e74525", "fy": "2027-28", "measure_key": "ab2026__pension_tax_allowance", "metric": "tax_liability", "reason": "worked_example", "source": "resolution_foundation"} {"claim_id": "4cb31af1e61a10478ceb", "fy": "2031-32", "measure_key": "ab2026__pension_tax_allowance", "metric": "revenue_change", "reason": "exchequer_component", "source": "obr_efo"} {"claim_id": "53f8834bc2f84cfe1371", "fy": "2029-30", "measure_key": "ab2026__pension_tax_allowance", "metric": "average_household_income_change", "reason": "vigintile_ahc_breakdown", "source": "resolution_foundation"} diff --git a/scorecard_db/baselines.py b/scorecard_db/baselines.py index 95a016bf1..bdec3dd02 100644 --- a/scorecard_db/baselines.py +++ b/scorecard_db/baselines.py @@ -417,12 +417,11 @@ "counterfactual": "policy_parameters", }, "obr_october_2026_budget_forecast__policy_parameters", - "The OBR's October 2026 Budget forecast, on the assumption that the " - "latest policy is implemented: the Autumn Budget 2026 measures, with " - "fuel duty rates frozen until July 2027 and raised from then. The OBR " - "costs a continued freeze against it (EFO October 2026, paragraphs " - "3.43 and 4.30). A post-measures world, deliberately not a " - "pre-measures one.", + "In its October 2026 forecast, the OBR assumes that the government " + "implements the Autumn Budget 2026 measures. The government freezes " + "fuel duty rates until July 2027 and raises them from then. The OBR " + "costs a continued freeze against that forecast (EFO October 2026, " + "paragraphs 3.43 and 4.30).", "policy_ref", "sources/harvest-uk-ab2026-2026-10-29/uk_obr_tables (proposed_baseline " "'OBR October 2026 forecast, on the assumption that the latest policy " diff --git a/scorecard_db/ingest_uk_ab2026.py b/scorecard_db/ingest_uk_ab2026.py index 0a664762d..f62f40440 100644 --- a/scorecard_db/ingest_uk_ab2026.py +++ b/scorecard_db/ingest_uk_ab2026.py @@ -38,17 +38,22 @@ 3. **Shares of GDP.** We put a ``percent`` row with a GDP denominator (IFS's) on the OBR's and TPA's ``percent_of_gdp``, which AB2025 drops as macro-fiscal. -4. **HM Treasury figures staged twice.** HM Treasury repeats 408 Table 6.1 - cells in the costings and 24 in red book Table 6.3 and its prose. We keep - the Table 6.1 or 6.2 claim, list each repetition under +4. **Figures a producer prints more than once.** HM Treasury repeats 408 + Table 6.1 cells in the costings and 24 in red book Table 6.3 and its + prose. We keep the Table 6.1 or 6.2 claim, list each repetition under ``publication.also_printed_in`` and tally it. We match a repetition by key, staged metric, unit, year and value. We also record nine reviewed red book printings in ``REVIEWED_TWINS``, where HM Treasury repeats a cell with - the opposite sign, a rounding or another year. + the opposite sign, a rounding or another year. In ``REPEATED_PRINTINGS`` + we merge 176 more rows on which a producer prints a figure it prints + elsewhere: in the same family, or for 60 rows of HM Treasury's costings, + in red book Table 6.3. We keep the most precise printing, and a point + value over a bound. 5. **Row calls.** We move IFS row 46 to another metric in ``ROW_METRICS``, give it a per-household unit in ``ROW_UNITS``, and tally 22 rows under six - reasons in ``ROW_DROPS``. With each entry we record the staged value we - expect on that row. + reasons in ``ROW_DROPS``. In ``ROW_TIME_BASES`` we give three red book + rows the time basis on which we stage another printing of their figure. + With each entry we record the staged value we expect on that row. 6. **Lanes.** We add three lanes: official, microsimulation, and administrative data and other producers. ``advance_lanes`` moves a lane to ``computed`` once its claims have counterparts, which @@ -69,6 +74,7 @@ from pathlib import Path from . import ingest_uk_ab2025 as AB25 +from . import signs from .db import DIAGNOSES_SQL, LANE_SQL, RESULTS_SQL, SCORES_SQL, ScorecardDB from .harvest import REPO, finish, merge_republications, with_baseline_condition from .models import ( @@ -170,6 +176,13 @@ "costings or Budget document, sometimes rounded or with the opposite " "sign. We score the table figure and list this printing with it." ), + "figure_printed_again": ( + "The producer prints this figure more than once: in prose and in a " + "table, a chart or its workbook, in two tables, or in two of its " + "documents. It sometimes rounds or bounds the figure, or gives it the " + "opposite sign. We score its most precise printing, and a point value " + "over a bound, and list this one with it." + ), "energy_bill_level_no_metric": ( "The producer gives the level of a typical household's energy bill " "under the price cap (RF's £2,210, for example), and we score changes " @@ -349,6 +362,36 @@ ROW_UNITS: dict[tuple[str, int], str] = {("uk_ifs_ab2026", 46): "gbp_per_household"} assert set(ROW_UNITS) <= set(ROW_METRICS) +# (family, row) -> (staged time basis, staged value_raw, the time basis the +# ingest stores, why). HM Treasury prints each of these figures on another row, +# where we stage it on the other basis, and we merge the two printings in +# REPEATED_PRINTINGS. +_ANNUAL_CAP = ( + "HM Treasury expects the government to take around £50 off the annual Ofgem " + "price cap in April 2027 by extending the VAT cut, a saving we stage as " + "annual on rows 188, 190 and 197." +) +_PAID_IN_JANUARY = ( + "HM Treasury counts up to 20 million households that the government pays " + "the Household Energy Payment from January 2027, a count we stage at that " + "point in time on row 7." +) +ROW_TIME_BASES: dict[tuple[str, int], tuple[str, str, str, str]] = { + ("uk_hmt_redbook", 5): ("point_in_time", "around £50", "annual", _ANNUAL_CAP), + ("uk_hmt_redbook", 180): ( + "annual", + "20 million", + "point_in_time", + _PAID_IN_JANUARY, + ), + ("uk_hmt_redbook", 189): ( + "annual", + "20 million", + "point_in_time", + _PAID_IN_JANUARY, + ), +} + # (family, row) -> (staged value_raw, drop reason) ROW_DROPS: dict[tuple[str, int], tuple[str, str]] = { ("uk_obr_tables", 2658): ( @@ -472,6 +515,1031 @@ def published(row: dict) -> bool: ("uk_hmt_redbook", i): (2026, 252, 2027) for i in (263, 271, 272) } +# Rows on which a producer prints a figure it prints elsewhere: in prose and in +# a table, a chart or the chart's workbook, in two tables, or in two of its +# documents. We map each (family, row) to the row whose claim we keep, and to +# our reading of the pair. We name the kept row's family where it differs from +# the repeat's, as for HM Treasury's costings and red book. The ingest raises +# if the two claims differ in key, metric, unit, year or time basis, or if the +# producer costs part of a measure in one and the whole measure in the other. +# It also raises if they differ in any condition outside ``_PER_PRINTING``, +# such as geography, population or scenario, unless we list the two wordings +# for that repeat in ``_SAME_READING``. Of two point values we keep the more +# precise, and the ingest raises if we keep the coarser, or if they differ by +# more than half the coarser printing's last digit. It also raises if they +# differ in estimate kind, as when the producer sums several years in one +# printing and gives one year in the other. Where the producer states each +# printing's sign convention, it compares the values in PolicyEngine's +# orientation, and otherwise it compares their magnitudes. Where a producer +# bounds a figure that it prints elsewhere as a point value, we keep the point +# value, and the ingest raises if we keep the bound. It compares the producer's +# own values, and raises if the two printings differ in sign convention, or if +# the point value lies more than half its last digit outside the bound. It also +# raises on two bounds of opposite directions. +_CENTAX_640 = ( + "CenTax prints the £640 million cost of removing the £100,000 childcare " + "threshold in two documents: the key findings of Taxes at the top, and " + "its reaction to the Budget." +) +_CENTAX_197 = ( + "CenTax estimates that the government would raise £19.7 billion in 2030 " + "if it reformed capital gains tax and taxed gains at income tax rates. " + "CenTax prints the estimate in the key findings of Taxes at the top, and " + "again in footnote 9 of its Unicorn Relief paper." +) +_CENTAX_14 = ( + "CenTax prints its 2024 estimate, £14 billion in 2026, in section 3.1 of " + "Taxes at the top, and again in footnote 9 of its Unicorn Relief paper." +) +_CENTAX_TABLE = "CenTax rounds Table 1's shares in the text of section 3.2." +_CENTAX_BOUND = ( + "In section 3.2 of Taxes at the top, CenTax says the bottom 50% would pay " + "less than 0.5% of the revenue from NICs on partnerships, and in Table 1 it " + "prints their share as 0.40%." +) +_HMT_30 = ( + "In its executive summary and Box 3.A, HM Treasury estimates that " + "billpayers save around £30 by 2030 under the Energy Debt Circuit Breaker. " + "In paragraph 3.8 it puts a typical household's saving under the same debt " + "strategy at almost £30 by 2030. We read one estimate of the saving." +) +_HMT_70K = ( + "In its executive summary HM Treasury expects the government to help " + "70,000 households onto the housing ladder through Your First Home, and in " + "paragraph 5.5 around 70,000 households in England." +) +_HMT_AI = ( + "In paragraph 2.15 the government puts £50 million into a Civil Service AI " + "transformation fund, and in paragraph 6.6 it funds the same £50 million " + "from savings in administration budgets." +) +_HMT_GAP = ( + "In footnote 73 HM Treasury counts £2.3 billion from this Budget's tax-gap " + "measures, rounding the +2,250m it prints in Table 6.3 for the subtotal " + "including the memo line in 2029-30." +) +_HMT_35M = ( + "HM Treasury counts 35 million motorists in paragraph 3.3 and again in " + "paragraph 3.13." +) +_HMT_50 = ( + "In its executive summary, in paragraphs 3.4 and 3.5 and in Box 3.A, HM " + "Treasury expects the government to take around £50 off the annual Ofgem " + "price cap in April 2027 by extending the VAT cut on domestic electricity." +) +_HMT_20M = ( + "HM Treasury counts up to 20 million households in England that the " + "government pays the Household Energy Payment, in its executive summary " + "and in paragraphs 2.48 and 3.5." +) +_HMT_15M = ( + "In paragraph 5.12 and again in paragraph 6.77, the government gives the " + "Office for the Impact Economy £15 million." +) +_HMT_DECILE = ( + "For its example in paragraph 2.10, HM Treasury gives a household of two " + "adults a gross income of £33,500, the figure it prints in Table 2.C for " + "two adults in the third decile." +) +_HMT_NADIA = ( + "In its worked example HM Treasury prints Nadia's £166 of income tax " + "twice, as the tax she owes and the tax she pays." +) +_HMT_TAX_GAP = ( + "HM Treasury prints each tax-gap measure's yield from 2026-27 to 2031-32 " + "in its policy costings and again in red book Table 6.3, where we keep it." +) +_IFS_80 = ( + "IFS prints one share, around 80% of households in England, in both its " + "initial response and Helen Miller's opening remarks." +) +_OBR_TOTAL = ( + "The OBR rounds the measure's Table 1.1 total for the year in its chapter 3 " + "text, to £0.1 billion or to £1 billion." +) +_OBR_T31 = ( + "The OBR prints this line in £ billion in Table 3.1, with a positive sign " + "for higher borrowing, and in £ million in Table 1.1 of its policy " + "workbook, with a negative sign for a cost to the Exchequer." +) +_OBR_T33 = ( + "The OBR prints the online marketplace measure's yield from 2027-28 to " + "2031-32 in Table 3.3, under the tax head, and in Table 1.1. It costs the " + "measure in VAT receipts alone, so it prints the same figures in both " + "tables, with opposite signs." +) +_OBR_DIRECT = ( + "In paragraph 3.2 the OBR puts the direct effect of policy measures at a " + "£12 billion cut in borrowing in 2031-32, rounding the 11,681 (£ million) " + "it prints in Table 1.1." +) +_OBR_DEPARTMENTS = ( + "In paragraph 3.11 the OBR rounds 2026-27's 5.4 (£ billion) on Table " + "3.1's line for other departmental spending changes to £5 billion." +) +_OBR_VAT = ( + "In paragraph 3.19 the OBR costs the VAT cut on domestic electricity at " + "£0.7 billion in 2026-27 and £0.3 billion in 2027-28, rounding the VAT " + "line of measure 2 in Table 1.1 (-734 and -296, £ million)." +) +_OBR_FOUNDERS = ( + "The OBR gives Founders' Relief's 2029-30 effect as a £0.3 billion cut in " + "receipts in paragraph 3.18, and as -261 (£ million) in Table 1.1, where " + "it prints a loss to the Exchequer as negative." +) +_RF_AGAIN = ( + "Resolution Foundation prints the figure, with the same meaning, in more " + "than one of its documents." +) +_RF_BOUND = ( + 'Resolution Foundation bounds the figure in one printing ("under £145", ' + '"over £130") and gives it in another; we keep the point value.' +) +_RF_WORKBOOK = ( + "Resolution Foundation rounds the figure in its text or on its chart, and " + "gives the unrounded value in the chart's workbook." +) +_RF_3PC = ( + "Resolution Foundation expects typical non-pensioner incomes to fall by 3 " + "per cent between 2026-27 and 2028-29 in a press release, and by 3.0 per " + "cent on its publication page." +) +_RF_HALF = ( + "On its publication page Resolution Foundation says just over half of the " + "cost of living support goes to the poorer half of households, and on " + "page 19 of its briefing it estimates 52 per cent." +) +_RF_MILLION = ( + "Resolution Foundation says over a million private renting families lose " + "out from the LHA freeze, and in its workbook for Figure 9 it counts " + "1,572,152 families who would gain if the government unfroze LHA." +) +_TPA_1BN = ( + "Tax Policy Associates gives the 2028/29 yield of Table 6.1 lines 61 and 62 " + "as £1.1bn, and calls it about £1bn in its section on savers and landlords." +) +_TPA_700M = ( + "Tax Policy Associates sums its groups to £700m in footnote 5, and prints " + "£0.7bn in its chart's description." +) +_TPA_19BN = ( + "Tax Policy Associates prints the real-terms total as £19.1bn in footnote 7 " + "and in its chart's description, and rounds it to £19bn in the text." +) +_TPA_6BN = ( + "Tax Policy Associates says only about £6bn of the 2030-31 tax rises in " + "2026 money comes from this Budget, and plots £5.9bn for it on its chart of " + "tax rises by fiscal event." +) +_TPA_CHART = ( + "Tax Policy Associates gives each group's 2027/28 value in two charts: it " + "labels the value on its chart of the 2027/28 measures by tax, and plots " + "it again on its chart of the changes by year." +) +REPEATED_PRINTINGS: dict[tuple[str, int], tuple[int | tuple[str, int], str]] = { + ("uk_centax", 25): (1, _CENTAX_640), + ("uk_centax", 107): (21, _CENTAX_197), + ("uk_centax", 108): (58, _CENTAX_14), + ("uk_centax", 62): (82, _CENTAX_TABLE), + ("uk_centax", 64): (67, _CENTAX_TABLE), + ("uk_centax", 65): (66, _CENTAX_BOUND), + ("uk_hmt_redbook", 194): (9, _HMT_30), + ("uk_hmt_redbook", 201): (9, _HMT_30), + ("uk_hmt_redbook", 256): (14, _HMT_70K), + ("uk_hmt_redbook", 265): (176, _HMT_AI), + ("uk_hmt_redbook", 181): (354, _HMT_GAP), + ("uk_hmt_redbook", 202): (187, _HMT_35M), + ("uk_hmt_redbook", 190): (188, _HMT_50), + ("uk_hmt_redbook", 197): (188, _HMT_50), + ("uk_hmt_redbook", 268): (258, _HMT_15M), + ("uk_hmt_redbook", 362): (400, _HMT_DECILE), + ("uk_hmt_redbook", 423): (422, _HMT_NADIA), + ("uk_hmt_redbook", 5): (188, _HMT_50), + ("uk_hmt_redbook", 180): (7, _HMT_20M), + ("uk_hmt_redbook", 189): (7, _HMT_20M), + # each measure's six years, from row 191 of the costings and row 273 of + # the red book + **{ + ("uk_hmt_costings", c + y): (("uk_hmt_redbook", t + y), _HMT_TAX_GAP) + for c, t in ( + (191, 273), + (197, 279), + (203, 285), + (209, 291), + (215, 297), + (221, 303), + (227, 309), + (235, 315), + (241, 321), + (247, 327), + ) + for y in range(6) + }, + ("uk_ifs_ab2026", 97): (91, _IFS_80), + ("uk_obr_tables", 2674): (537, _OBR_FOUNDERS), + ("uk_obr_tables", 2672): (1005, _OBR_TOTAL), + ("uk_obr_tables", 2667): (1167, _OBR_TOTAL), + ("uk_obr_tables", 2531): (1183, _OBR_TOTAL), + ("uk_obr_tables", 2673): (1347, _OBR_TOTAL), + ("uk_obr_tables", 2526): (2171, _OBR_TOTAL), + ("uk_obr_tables", 2520): (2501, _OBR_DIRECT), + ("uk_obr_tables", 2655): (2570, _OBR_DEPARTMENTS), + ("uk_obr_tables", 2680): (18, _OBR_VAT), + ("uk_obr_tables", 2681): (19, _OBR_VAT), + # Table 3.1's lines in 2026-27 to 2031-32, from its row to Table 1.1's + **{ + ("uk_obr_tables", t31 + y): (t11 + y, _OBR_T31) + for t31, t11 in ( + (2540, 2352), # the direct effect of spending measures + (2552, 2514), # indirect effects of Government decisions + (2558, 2496), # direct effects of Government decisions + (2564, 6), # the council tax rebate, measure 1 + (2576, 2184), # the net impact of the unfunded pensions valuation + (2630, 2502), # decisions on HM Treasury's policy decisions table + (2636, 2508), # decisions not on that table + ) + for y in range(6) + }, + **{("uk_obr_tables", 2712 + y): (943 + y, _OBR_T33) for y in range(5)}, + ("uk_rf_ab2026", 177): (13, _RF_AGAIN), + ("uk_rf_ab2026", 28): (74, _RF_BOUND), + ("uk_rf_ab2026", 29): (76, _RF_BOUND), + ("uk_rf_ab2026", 54): (34, _RF_AGAIN), + ("uk_rf_ab2026", 127): (34, _RF_AGAIN), + ("uk_rf_ab2026", 93): (47, _RF_AGAIN), + ("uk_rf_ab2026", 61): (56, _RF_AGAIN), + ("uk_rf_ab2026", 63): (57, _RF_AGAIN), + ("uk_rf_ab2026", 133): (4, _RF_AGAIN), + ("uk_rf_ab2026", 153): (12, _RF_AGAIN), + ("uk_rf_ab2026", 41): (49, _RF_3PC), + ("uk_rf_ab2026", 48): (130, _RF_HALF), + ("uk_rf_ab2026", 58): (383, _RF_MILLION), + ("uk_rf_ab2026", 137): (383, _RF_MILLION), + ("uk_rf_ab2026", 59): (379, _RF_WORKBOOK), + ("uk_rf_ab2026", 138): (379, _RF_WORKBOOK), + ("uk_rf_ab2026", 77): (382, _RF_WORKBOOK), + ("uk_rf_ab2026", 147): (433, _RF_WORKBOOK), + ("uk_rf_ab2026", 148): (434, _RF_WORKBOOK), + ("uk_rf_ab2026", 149): (435, _RF_WORKBOOK), + ("uk_rf_ab2026", 150): (436, _RF_WORKBOOK), + ("uk_rf_ab2026", 151): (437, _RF_WORKBOOK), + ("uk_rf_ab2026", 198): (633, _RF_WORKBOOK), + ("uk_rf_ab2026", 200): (631, _RF_WORKBOOK), + ("uk_rf_ab2026", 60): (765, _RF_WORKBOOK), + ("uk_rf_ab2026", 205): (765, _RF_WORKBOOK), + ("uk_rf_ab2026", 208): (763, _RF_WORKBOOK), + ("uk_rf_ab2026", 209): (764, _RF_WORKBOOK), + ("uk_tpa", 2): (104, _TPA_6BN), + ("uk_tpa", 8): (6, _TPA_1BN), + ("uk_tpa", 168): (25, _TPA_700M), + ("uk_tpa", 4): (27, _TPA_19BN), + ("uk_tpa", 264): (27, _TPA_19BN), + ("uk_tpa", 224): (157, _TPA_CHART), + ("uk_tpa", 206): (158, _TPA_CHART), + ("uk_tpa", 212): (160, _TPA_CHART), + ("uk_tpa", 194): (163, _TPA_CHART), + ("uk_tpa", 176): (166, _TPA_CHART), +} + + +def _kept_row(family: str, k: int | tuple[str, int]) -> tuple[str, int]: + """The (family, row) whose claim we keep for a repeat in ``family``.""" + return k if isinstance(k, tuple) else (family, k) + + +_KEPT_ROWS = {_kept_row(fam, k) for (fam, _), (k, _) in REPEATED_PRINTINGS.items()} +_PRINTING_ROWS = set(REPEATED_PRINTINGS) | _KEPT_ROWS +assert not _KEPT_ROWS & set(REPEATED_PRINTINGS), ( + "we keep a row that we also drop as a repeat" +) +# We read these conditions as belonging to each printing rather than to the +# figure, and the ingest compares every other condition of a repeat and the +# printing we keep. It compares each printing's value, sign convention and +# estimate kind when it checks that the values agree. In the identity it +# compares the reform key, which we take from the registry measure or, for a +# row we don't key to a measure, from the first 120 characters of its reform +# hint (AB25._reform). In the other keys we record where, and in which version +# of a document, the producer prints the figure. +_PER_PRINTING = frozenset( + { + "value_verbatim", + "sign_convention", + "estimate_kind", + "reform_hint", + "table", + "table_line", + "table_row", + "sheet_section", + "chart_label", + "costing_leg_heading", + "heading", + "paragraph_heading", + "document_position", + "document_version", + } +) +# We read a claim without an income group as covering everyone, and one without +# a component as covering the whole measure. +_UNSTATED = {"income_group": "all", "component": "Total"} + + +def _costs_part(s: ExternalScore) -> bool: + """Whether the producer costs part of a measure in this printing: we + stage it with a component other than the measure's total, or as a + measure component.""" + c = s.conditions + named = c.get("component") not in (None, _UNSTATED["component"]) + return named or c.get("row_type") == "measure_component" + + +def _rows(family: str, *rows: int | range) -> frozenset[tuple[str, int]]: + """Return (family, row) for each row we name, and for each row in each range.""" + return frozenset( + (family, i) for r in rows for i in (r if isinstance(r, range) else (r,)) + ) + + +# HM Treasury costs each of the ten measures in its package to close the tax +# gap in six years, one row a year. On six of the rows it costs the measure +# under which HMRC expands its compliance workforce. +_TAX_GAP = _rows("uk_hmt_costings", range(191, 233), range(235, 253)) +_TAX_COMPLIANCE = _rows("uk_hmt_costings", range(235, 241)) +# For each group of repeats we list the conditions that we stage with one +# wording on the repeat and another on the printing we keep. We write each as +# (key, the repeat's wording, the kept printing's wording), and where we don't +# stage the condition on one printing, we write None for its wording. The +# ingest accepts a wording for the repeats we list it with, and raises on any +# other repeat that differs in it. +_Wording = tuple[str, str | None, str | None] +_READINGS: tuple[tuple[frozenset[tuple[str, int]], tuple[_Wording, ...]], ...] = ( + # On the printing of the £19.7 billion in the key findings of Taxes at the + # top, we note the OBR's £32 billion baseline forecast for capital gains + # tax from page 17. + ( + _rows("uk_centax", 107), + ( + ( + "baseline_forecast", + None, + "OBR baseline forecast of £32 billion for CGT (p. 17)", + ), + ), + ), + # In each year note we record how we date the printing. CenTax prints 2030 + # with both printings of the £640 million, and we record the year in the + # kept printing's note alone. CenTax prints a year with one printing of + # the £14 billion but not with the other, and no year with either + # printing of the three shares in section 3.2 and Table 1 of Taxes at the + # top. + ( + _rows("uk_centax", 25), + ( + ( + "year_note", + "CenTax gives tax years as the later year ('2022 is tax year 2021-22', Taxes at the top fn 2)", + "'in 2030'; CenTax gives tax years as the later year ('2022 is tax year 2021-22', Taxes at the top fn 2)", + ), + ), + ), + ( + _rows("uk_centax", 108), + ( + ( + "year_note", + "CenTax gives tax years as the later year ('2022 is tax year 2021-22', Taxes at the top fn 2)", + "the 2024 estimate was for 2026; CenTax gives tax years as the later year ('2022 is tax year 2021-22', Taxes at the top fn 2)", + ), + ), + ), + ( + _rows("uk_centax", 62, 64, 65), + ( + ( + "year_note", + "no year in the sentence; staged with the 2030 costing it describes; CenTax gives tax years as the later year ('2022 is tax year 2021-22', Taxes at the top fn 2)", + "no year printed with the table; staged with the 2030 costing", + ), + ), + ), + # HM Treasury costs each of the ten measures in its package to close the + # tax gap in its policy costings, and prints the same figures in red book + # Table 6.3. On the costings' rows we record the package's Table 6.1 line, + # 45, the impact channel and the National Accounts basis that HM Treasury + # states on page 10. We label the costings' basis a forecast and Table + # 6.3's post-behavioural, though in both HM Treasury prints the costing + # after any behavioural effect. + ( + _TAX_GAP, + ( + ("basis", "forecast", "post_behavioural"), + ("impact_channel", "tax_measure", None), + ( + "national_accounts_basis", + "All costings are presented on a National Accounts basis (p.10)", + None, + ), + ("table_61_line", "45", None), + ), + ), + # On the costings' rows we also record whether HM Treasury includes a + # behavioural effect, and quote HM Treasury where it says a measure has + # none, or has no static impact on taxpayer liabilities. + ( + _TAX_GAP - _TAX_COMPLIANCE, + (("behavioural_adjustment", "included (see note)", None),), + ), + ( + _TAX_COMPLIANCE, + (("behavioural_adjustment", "none: 'There is no behavioural effect.'", None),), + ), + ( + _rows("uk_hmt_costings", range(191, 197)), + ( + ( + "static_impact", + "none: 'The costing has no static impact on taxpayer liabilities.'", + None, + ), + ), + ), + ( + _rows("uk_hmt_costings", range(197, 203)), + ( + ( + "static_impact", + "none: 'The measure has no static impact on taxpayer liabilities.'", + None, + ), + ), + ), + # We record each tax-gap measure's full name on its costings' rows and a + # short name on red book Table 6.3's rows. + ( + _rows("uk_hmt_costings", range(191, 197)), + ( + ( + "component", + "E-invoicing: HMRC will require VAT invoices to be issued in a specified electronic format from 1 April 2029", + "E-invoicing (Table 6.3 row 1)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(197, 203)), + ( + ( + "component", + "Employment expenses: Remove the £2,500 Income Tax Self Assessment expenses threshold from 6 April 2028", + "Reforming employment expenses (Table 6.3 row 2)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(203, 209)), + ( + ( + "component", + "More Timely Payment: Require Income Tax Self Assessment taxpayers to pay more of their liabilities in-year from 2029", + "More timely payment for Self Assessment (Table 6.3 row 3)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(209, 215)), + ( + ( + "component", + "VAT and PAYE: Require direct debit arrangements for VAT and PAYE return liabilities from 1 and 6 April 2029 respectively", + "Direct debit for VAT and PAYE (Table 6.3 row 4)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(215, 221)), + ( + ( + "component", + "Real Estate: Participate in a new international agreement to automatically exchange information on real estate from 2029-30", + "Real estate information exchange (Table 6.3 row 5)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(221, 227)), + ( + ( + "component", + "Debt Management: Enable HMRC to recover lower value tax debts from the bank accounts of taxpayers who can afford to pay but repeatedly fail to do so from July 2029", + "Debt management: recovery from bank accounts (Table 6.3 row 6)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(227, 233)), + ( + ( + "component", + "Debt Management: Invest in HMRC's debt management to collect more overdue tax debts", + "Debt management: investment in HMRC debt collection (Table 6.3 row 7)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(235, 241)), + ( + ( + "component", + "Tax Compliance: Expand investment in HMRC's compliance workforce to recruit an additional 670 officers by 2029-30", + "Tax compliance: additional HMRC compliance officers (Table 6.3 row 8)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(241, 247)), + ( + ( + "component", + "Making Tax Digital (MTD) for Income Tax Self Assessment: Introduce a 12 month penalty easement for taxpayers joining MTD for Income Tax from 6 April 2027", + "MTD for Income Tax Self Assessment penalty easement (Table 6.3 row 9)", + ), + ), + ), + ( + _rows("uk_hmt_costings", range(247, 253)), + ( + ( + "component", + "Image Rights: Delay the implementation of legislation to clarify the tax treatment of image rights by one year to 6 April 2028", + "Image rights legislation delay (Table 6.3 row 10)", + ), + ), + ), + # HM Treasury names the annual Ofgem price cap and April 2027 in both + # printings of the £50. We record them, with a static basis, on the + # executive summary's printing and not on paragraph 3.4's. + ( + _rows("uk_hmt_redbook", 5), + ( + ("basis", "static", None), + ("date", "April 2027", None), + ("subgroup", "Ofgem price cap", None), + ), + ), + # In paragraph 3.5 HM Treasury describes a £100 payment to households in + # council tax bands A to D in England from January 2027. We record the + # bands, the date and a static basis on the executive summary's count of up + # to 20 million households, and not on paragraphs 2.48 and 3.5. + ( + _rows("uk_hmt_redbook", 180, 189), + ( + ("basis", None, "static"), + ("date", None, "January 2027"), + ("subgroup", None, "council tax bands A-D"), + ), + ), + # We record the basis and scoring method on Table 6.3's subtotal including + # the memo line, and not on footnote 73's £2.3 billion. + ( + _rows("uk_hmt_redbook", 181), + ( + ("basis", None, "post_behavioural"), + ("scoring_method", None, "final"), + ), + ), + # HM Treasury names all billpayers in its executive summary and Box 3.A, + # and a typical household in paragraph 3.8, and we read the three printings + # as one estimate of the saving. We record a static basis on the summary's + # printing, and the comparison without the strategy's measures on paragraph + # 3.8's. + ( + _rows("uk_hmt_redbook", 194, 201), + (("basis", None, "static"),), + ), + ( + _rows("uk_hmt_redbook", 194), + ( + ("comparison", "without strategy measures", None), + ("subgroup", "typical household", "all billpayers"), + ), + ), + # In both printings HM Treasury expects Your First Home to help about + # 70,000 households in England onto the housing ladder. On the executive + # summary's printing we record the scheme's first-time buyers, its lifetime + # and a static basis, and we note the period differently on the two. + ( + _rows("uk_hmt_redbook", 256), + ( + ("basis", None, "static"), + ("horizon", None, "scheme lifetime"), + ( + "period_detail", + None, + "Budget announcement; period of application as described in quote", + ), + ( + "period_interpretation", + "publication-year policy observation; printed horizon retained without an inferred endpoint", + None, + ), + ("subgroup", None, "first-time buyers"), + ), + ), + # We label chapter 6's printings of the £50 million Civil Service AI + # transformation fund and the £15 million for misogyny prevention as policy + # announcements. We date paragraph 6.6's £50 million by paragraph 2.15, and + # note the period of the £15 million differently on its two printings. + ( + _rows("uk_hmt_redbook", 265), + ( + ("basis", "policy_announcement", None), + ( + "horizon", + "across 2027-28 and 2028-29 (para 2.15)", + "across 2027-28 and 2028-29", + ), + ), + ), + ( + _rows("uk_hmt_redbook", 268), + ( + ("basis", "policy_announcement", None), + ( + "period_detail", + "Budget announcement year; no specific year stated for this quantity in the paragraph", + None, + ), + ( + "period_interpretation", + None, + "publication-year policy observation; printed horizon retained without an inferred endpoint", + ), + ), + ), + # We record the statistic, a median, on Table 2.C's cell and not on + # paragraph 2.10's example. + ( + _rows("uk_hmt_redbook", 362), + (("statistic", None, "median"),), + ), + # In its worked example HM Treasury says Nadia owes £166 of income tax, and + # then that she pays it. + ( + _rows("uk_hmt_redbook", 423), + (("quantity", "income tax paid", "income tax liability"),), + ), + # We give IFS's initial response a reference date of 28 October and Helen + # Miller's opening remarks one of 29 October. On the remarks' printing of + # the 80% we also record council tax bands A to D. + ( + _rows("uk_ifs_ab2026", 97), + ( + ("eligibility", "council tax bands A-D", None), + ("reference_date", "2026-10-29", "2026-10-28"), + ), + ), + # The OBR words two lines of Table 1.1 differently in Table 3.1 and in + # paragraph 3.2. + ( + _rows("uk_obr_tables", 2520), + ( + ( + "component", + "Direct effect of policy measures (para 3.2)", + "Direct effect of Government decisions", + ), + ), + ), + ( + _rows("uk_obr_tables", range(2552, 2558)), + ( + ( + "component", + "Indirect effects of Government decisions", + "Indirect effect of Government decisions", + ), + ), + ), + ( + _rows("uk_obr_tables", range(2558, 2564)), + ( + ( + "component", + "Direct effects of Government decisions", + "Direct effect of Government decisions", + ), + ), + ), + # On the rows of the OBR's policy workbook we mark each measure's total, + # and record the measure's Table 6.1 line and the fiscal head and category + # that the OBR gives it. We record none of these on the OBR's chapter 3 + # text or its Tables 3.1 and 3.3. The OBR labels two of Table 3.1's lines, + # the direct effects of decisions on and off HM Treasury's policy decisions + # table, as memo lines, and we mark their scoring as memo. We mark the + # scoring of the other rows of these tables and of the workbook as final, + # and leave the OBR's chapter 3 text unmarked. In Table 3.3 we record that + # the OBR lists the online marketplace measure under tax and rates the + # uncertainty of its costing as high. + ( + _rows( + "uk_obr_tables", + 2526, + 2531, + 2667, + range(2564, 2570), + range(2576, 2582), + range(2672, 2675), + range(2712, 2717), + ), + ( + ("fiscal_head", None, "Total"), + ("row_type", None, "measure_total"), + ), + ), + ( + _rows("uk_obr_tables", range(2540, 2546), range(2630, 2642)), + (("row_type", None, "measure_total"),), + ), + ( + _rows("uk_obr_tables", 2680, 2681), + ( + ("category", None, "VAT"), + ("fiscal_head", None, "Receipts"), + ("table_61_line", None, "2"), + ), + ), + ( + _rows("uk_obr_tables", range(2564, 2570)), + (("table_61_line", None, "1"),), + ), + ( + _rows("uk_obr_tables", range(2712, 2717)), + ( + ("head", "Tax", None), + ("table_61_line", None, "46"), + ("uncertainty_rating", "High", None), + ), + ), + ( + _rows("uk_obr_tables", 2531), + (("table_61_line", None, "55"),), + ), + ( + _rows("uk_obr_tables", 2667), + (("table_61_line", None, "54"),), + ), + ( + _rows("uk_obr_tables", 2672), + (("table_61_line", None, "49"),), + ), + ( + _rows("uk_obr_tables", 2673), + (("table_61_line", None, "60"),), + ), + ( + _rows("uk_obr_tables", 2674), + (("table_61_line", None, "26"),), + ), + ( + _rows( + "uk_obr_tables", 2520, 2526, 2531, 2655, 2667, range(2672, 2675), 2680, 2681 + ), + (("scoring_method", None, "final"),), + ), + ( + _rows("uk_obr_tables", range(2630, 2642)), + (("scoring_method", "memo", "final"),), + ), + # In our notes on these horizons and on the costing basis we cite pages of + # Spread thin, the briefing by Resolution Foundation (RF). We word each + # note for the document in which RF prints the figure. + ( + _rows("uk_rf_ab2026", 127), + ( + ( + "costing_basis", + "Fuel Duty counted at the share accruing directly to households (fn 19)", + "Fuel Duty counted at the share accruing directly to households (Spread thin fn 19)", + ), + ( + "horizon", + "2025-26 and 2026-27 (as printed)", + "years not printed in the release (Spread thin p.19 prints '2025-26 and 2026-27')", + ), + ), + ), + ( + _rows("uk_rf_ab2026", 54), + ( + ( + "horizon", + "years not printed on the page (Spread thin p.19 prints '2025-26 and 2026-27')", + "years not printed in the release (Spread thin p.19 prints '2025-26 and 2026-27')", + ), + ), + ), + ( + _rows("uk_rf_ab2026", 93), + ( + ( + "horizon", + "2026-27 and 2027-28 (p.17: £3.4bn and £0.3bn)", + "2026-27 and 2027-28 (Spread thin p.17: £3.4bn and £0.3bn)", + ), + ), + ), + # We record Figure 8's notes on where RF models each measure on page 19's + # 52 per cent, and not on the publication page's 'just over half'. + ( + _rows("uk_rf_ab2026", 48), + ( + ( + "modelling_geography", + None, + "Council Tax and VAT cuts modelled for Great Britain only; Fuel Duty for the UK (Figure 8 notes)", + ), + ), + ), + # In its text RF counts the private renting families who lose out when the + # government extends the LHA freeze. In Figure 9's workbook it labels the + # same families as those who would gain if the government unfroze LHA. For + # Your First Home it counts renter households with the resources to access + # the scheme in its text, and families who could access it in the workbook. + # On the workbook's cells we record the benefit units that RF counts and + # its ranking by income after housing costs. On the text's printings we + # record the halves of the income distribution that RF names, or our note + # on the freeze. + ( + _rows("uk_rf_ab2026", 58, 59, 77, 137, 138), + (("housing_costs", None, "ahc"),), + ), + ( + _rows("uk_rf_ab2026", 58, 137), + ( + ( + "framing", + "RF: lose out from prolonging the LHA freeze into 2027-28; they would gain if LHA were unfrozen", + None, + ), + ( + "income_axis", + None, + "net equivalised household income decile, after housing costs", + ), + ), + ), + ( + _rows("uk_rf_ab2026", 59, 77, 138), + ( + ( + "income_axis", + "household income distribution, split at the median (RF: poorer / richer half)", + "net equivalised household income decile, after housing costs", + ), + ("unit_population", None, "private renting families (benefit units)"), + ), + ), + ( + _rows("uk_rf_ab2026", 59, 138), + ( + ( + "denominator", + "private renting families who lose out from the prolonged LHA freeze", + "private renting families who would benefit if LHA were unfrozen", + ), + ), + ), + ( + _rows("uk_rf_ab2026", 77), + ( + ( + "denominator", + "private renter households with the resources to access Your First Home", + "private renting families who could access Your First Home", + ), + ), + ), + # On page 24 of Spread thin RF compares receipts with a path on which the + # government raised Fuel Duty with RPI from January 2011. In its press + # release it compares them with the rises the government planned over the + # past 15 years. We read both as the same path of rates. + ( + _rows("uk_rf_ab2026", 153), + ( + ( + "counterfactual", + "Fuel Duty rates risen in line with RPI since January 2011", + "planned Fuel Duty rises delivered over the past 15 years", + ), + ), + ), + # On Figure 23's points we note a change since 2023-24, and on the + # workbook's cells for 2028-29 a change from 2023-24 to 2028-29. + ( + _rows("uk_rf_ab2026", 208, 209), + (("horizon", "change since 2023-24", "2023-24 to 2028-29"),), + ), + # We word RF's median and its population in full on the press release's + # printing of the fall in typical non-pensioner incomes, and in short on + # the publication page's. + ( + _rows("uk_rf_ab2026", 41), + ( + ("statistic", "median real annual disposable income", "median"), + ( + "unit_population", + "working-age (non-pensioner) households", + "non-pensioners", + ), + ), + ), + # On the press release's printing we record council tax bands E and above + # for the households in higher-band properties that miss out on the + # Household Energy Payment. + ( + _rows("uk_rf_ab2026", 133), + ( + ( + "subgroup", + "live in higher-band properties and will miss out on the Household Energy Payment", + "live in higher-band properties (Council Tax bands E and above) and miss out on the Household Energy Payment", + ), + ), + ), + # In our notes we trace the £6 billion in the text of Tax Policy Associates + # (TPA) to Table 6.1's total in today's money. We trace the £5.9 billion on + # its chart to its grouping of the OBR's costings by fiscal event in 2026 + # money, under the series 'Healey Oct 2026 Budget'. + ( + _rows("uk_tpa", 2), + ( + ( + "derived_from", + "HM Treasury Budget 2026 Table 6.1 total tax policy decisions, in 2026 money", + "OBR costings of tax measures announced since 2020, grouped by TPA by fiscal event", + ), + ("policy_event", None, "Healey Oct 2026 Budget"), + ("price_basis", "today's money (2026)", "2026 money"), + ), + ), + # TPA prints no year with its 'about £1bn' from savers and landlords, and + # in a note on that printing we date it at 2028-29, the year that TPA gives + # with its £1.1 billion. + ( + _rows("uk_tpa", 8), + ( + ( + "year_note", + "no year stated ('it will be permanent'); staged at 2028-29, the first full year of the rise", + None, + ), + ), + ), + # TPA sums its groups of Table 6.1's tax rows to £700m in footnote 5 and to + # £0.7 billion in its chart's description, and we describe the sum in + # different words on each. + ( + _rows("uk_tpa", 168), + ( + ( + "derived_from", + "HM Treasury Budget 2026 Table 6.1 tax rows, summed by TPA's groups", + "HM Treasury Budget 2026 Table 6.1, tax rows (53 lines)", + ), + ("measure_type", None, "sum of TPA's groups of the Table 6.1 tax rows"), + ), + ), + # We record TPA's deflator on footnote 7's £19.1 billion, and not on the + # text's £19 billion or the chart description's £19.1 billion. On the + # text's printing we give the same source and price basis in more words. + ( + _rows("uk_tpa", 4, 264), + ( + ( + "deflator", + None, + "OBR CPI forecast (EFO Table A.1), 2.0% assumed for 2032", + ), + ), + ), + ( + _rows("uk_tpa", 4), + ( + ( + "derived_from", + "HM Treasury Budget 2026 Table 6.1 tax lines, deflated by the OBR's October 2026 CPI forecast", + "HM Treasury Budget 2026 Table 6.1 tax rows, deflated", + ), + ("price_basis", "2026-27 prices (footnote 7)", "2026-27 prices"), + ), + ), +) +_SAME_READING = frozenset( + (family, i, *wording) + for repeats, wordings in _READINGS + for family, i in repeats + for wording in wordings +) + def _is_component(row: dict) -> bool: """A part of a measure (rule 9), which is never a twin of the whole.""" @@ -724,6 +1792,12 @@ def _check_row_calls(family: str, rows: list[dict]) -> None: for (fam, i), (raw, _) in ROW_DROPS.items(): if fam == family and rows[i]["value_raw"] != raw: raise ValueError(f"ROW_DROPS {fam} row {i} no longer matches") + for (fam, i), (basis, raw, _, _) in ROW_TIME_BASES.items(): + if fam == family and (rows[i]["time_basis"], rows[i]["value_raw"]) != ( + basis, + raw, + ): + raise ValueError(f"ROW_TIME_BASES {fam} row {i} no longer matches") reviewed = {i: v for (fam, i), v in REVIEWED_TWINS.items() if fam == family} if reviewed: table = _load("uk_hmt_tables") @@ -744,6 +1818,122 @@ def _check_row_calls(family: str, rows: list[dict]) -> None: raise ValueError(f"REVIEWED_TWINS {family} row {i} no longer matches") +_NUMBER = re.compile(r"(\d[\d,]*)(?:\.(\d+))?") + + +def _printed_place(s: ExternalScore) -> float: + """Return the place value of a printing's last digit in the claim's units: + £100m for "£2.6 billion", 0.01 for "91 per cent" on a share. For a + printing without digits ("over a million"), or a value of zero, we + return 0. + + We raise unless the value equals the printed number times a power of + ten. We fold any workbook exponent into that power, so we read the digits + before "E" and ignore the exponent.""" + printed = _NUMBER.search(s.conditions["value_verbatim"]) + if printed is None or s.value == 0: + return 0.0 + whole, places = printed.groups() + number = float(whole.replace(",", "") + "." + (places or "0")) + if number == 0: + return 0.0 + scale = abs(s.value) / number + unit = 10.0 ** round(math.log10(scale)) + if not math.isclose(scale, unit, rel_tol=1e-9): + raise ValueError(f"{s.value} doesn't match printed {printed[0]!r}") + return unit * 10.0 ** -len(places or "") + + +def _relation(s: ExternalScore) -> str: + """How the producer's sign on this printing relates to PolicyEngine's + (scorecard_db.signs).""" + return signs.classify( + { + "metric": s.metric.value, + "conditions": s.conditions, + "country": "UK", + "source": s.source, + } + )[0] + + +def _signed_values(a: ExternalScore, b: ExternalScore) -> tuple[float, float]: + """Return both values in PolicyEngine's orientation where the producer + states each printing's sign convention (scorecard_db.signs), and + otherwise both magnitudes.""" + relations = [_relation(s) for s in (a, b)] + if set(relations) <= {signs.SAME, signs.OPPOSITE}: + return ( + signs.external_value_pe_sign(a.value, relations[0]), + signs.external_value_pe_sign(b.value, relations[1]), + ) + return abs(a.value), abs(b.value) + + +_BOUNDS = {"range_low", "range_high"} + + +def _within_half(a: float, b: float, place: float) -> bool: + """Whether a and b differ by at most half of ``place``. In binary floating + point, 0.58 - 0.575 = 0.0050000000000000044, so we allow a few units in the + last place of each operand.""" + slack = 4 * (math.ulp(a) + math.ulp(b) + math.ulp(place)) + return abs(a - b) <= place / 2 + slack + + +def _within_bound(bound: ExternalScore, point: ExternalScore, place: float) -> bool: + """Whether a point value printed to ``place`` lies within a bound + printing: at or above a lower bound ("over a million"), or at or below an + upper bound ("under £145"). The point may lie up to half its last digit past + the bound, because the producer may have rounded it across. We compare the + producer's own values, so the two printings must share a sign convention.""" + if _relation(bound) != _relation(point): + return False + inside = ( + point.value >= bound.value + if bound.conditions["estimate_kind"] == "range_low" + else point.value <= bound.value + ) + return inside or _within_half(point.value, bound.value, place) + + +def _check_printing(family: str, i: int, repeat: ExternalScore, kept: ExternalScore): + def identity(s: ExternalScore) -> tuple: + return ( + s.source, + s.reform.key(), + s.metric, + s.unit_concept, + s.period, + s.time_basis, + s.period_start, + s.period_end, + _costs_part(s), + ) + + a, b = _signed_values(repeat, kept) + coarse, fine = _printed_place(repeat), _printed_place(kept) + kinds = [s.conditions.get("estimate_kind") for s in (repeat, kept)] + bound = [kind in _BOUNDS for kind in kinds] + if bound == [True, False]: + agree = _within_bound(repeat, kept, fine) + elif bound == [False, True]: + agree = False # we never keep a bound over a point value + else: + agree = kinds[0] == kinds[1] and fine <= coarse and _within_half(a, b, coarse) + keys = ( + repeat.conditions.keys() | kept.conditions.keys() | _UNSTATED.keys() + ) - _PER_PRINTING + first, second = ( + {k: s.conditions.get(k, _UNSTATED.get(k)) for k in keys} for s in (repeat, kept) + ) + reworded = { + (family, i, k, first[k], second[k]) for k in keys if first[k] != second[k] + } + if identity(repeat) != identity(kept) or reworded - _SAME_READING or not agree: + raise ValueError(f"REPEATED_PRINTINGS {family} row {i} no longer matches") + + def stage(families: dict | None = None) -> tuple[list[ExternalScore], dict]: """Stage every ingestible row; nothing touches the DB here. @@ -755,6 +1945,7 @@ def stage(families: dict | None = None) -> tuple[list[ExternalScore], dict]: acct = {"read": 0, "ingested": 0, "dropped": 0, "by_family": {}, "drops": {}} canonical: dict[tuple, ExternalScore] = {} table_claims: dict[int, ExternalScore] = {} + printed: dict[tuple[str, int], ExternalScore] = {} for family, (lane, sources) in FAMILIES.items(): if families is None: loaded = _load(family) @@ -801,6 +1992,8 @@ def stage(families: dict | None = None) -> tuple[list[ExternalScore], dict]: ) if (family, i) in ROW_UNITS: row = {**row, "unit_concept": ROW_UNITS[(family, i)]} + if (family, i) in ROW_TIME_BASES: + row = {**row, "time_basis": ROW_TIME_BASES[(family, i)][2]} twin = _twin_key(row, name) kept = None if family in _TWIN_FAMILIES and (family, i) in REVIEWED_TWINS: @@ -819,6 +2012,8 @@ def stage(families: dict | None = None) -> tuple[list[ExternalScore], dict]: _drop(acct, fam, "hmt_figure_staged_twice") continue score = _score(row, family, source, metric) + if (family, i) in _PRINTING_ROWS: + printed[(family, i)] = score if family == "uk_hmt_tables": table_claims[i] = score if twin is not None: @@ -827,6 +2022,45 @@ def stage(families: dict | None = None) -> tuple[list[ExternalScore], dict]: fam["ingested"] += 1 acct["ingested"] += 1 acct["by_family"][family] = fam + # Figures a producer prints more than once (REPEATED_PRINTINGS). When we + # stage a sample of rows, as we do in tests, we skip a pair unless we stage + # both its rows. + repeats: set[int] = set() + # a dropped repeat's claim id -> the claims we merged it into + targets: dict[str, set[int]] = {} + for (family, i), (k, _) in sorted(REPEATED_PRINTINGS.items()): + kept_row = _kept_row(family, k) + repeat, kept = printed.get((family, i)), printed.get(kept_row) + if repeat is None or kept is None: + if families is None: + raise ValueError( + f"no claim from REPEATED_PRINTINGS {family} row {i} or its " + f"kept row {kept_row[1]}" + ) + continue + _check_printing(family, i, repeat, kept) + kept.publication.setdefault("also_printed_in", []).append( + { + "family": family, + "table": repeat.publication.get("table"), + "locator": repeat.publication.get("locator"), + "source_column": repeat.source_column or None, + "value_verbatim": repeat.conditions["value_verbatim"], + } + ) + repeats.add(id(repeat)) + targets.setdefault(repeat.claim_id(), set()).add(id(kept)) + fam = acct["by_family"][family] + fam["ingested"] -= 1 + acct["ingested"] -= 1 + _drop(acct, fam, "figure_printed_again") + scores = [s for s in scores if id(s) not in repeats] + # We raise if a claim we keep shares its id with a repeat we dropped, unless + # we merged that repeat into the claim itself. Had we kept the repeat, + # merge_republications would have merged the two, so unless we also list + # that claim's row in REPEATED_PRINTINGS, we would score the figure twice. + if any(id(s) not in targets.get(s.claim_id(), {id(s)}) for s in scores): + raise ValueError("we keep a claim that shares its id with a repeat we dropped") # One producer's twin printings within a family (AB2025's merge). merged: list[ExternalScore] = [] for source in sorted({s.source for s in scores}): diff --git a/scorecard_db/ingest_uk_ab2026_expected.json b/scorecard_db/ingest_uk_ab2026_expected.json index e4baee425..cb2eac6ae 100644 --- a/scorecard_db/ingest_uk_ab2026_expected.json +++ b/scorecard_db/ingest_uk_ab2026_expected.json @@ -1,7 +1,7 @@ { "read": 5959, - "ingested": 4688, - "dropped": 1271, + "ingested": 4514, + "dropped": 1445, "by_family": { "uk_hmt_tables": { "read": 768, @@ -10,28 +10,28 @@ }, "uk_hmt_costings": { "read": 597, - "ingested": 172, - "dropped": 425 + "ingested": 112, + "dropped": 485 }, "uk_hmt_redbook": { "read": 425, - "ingested": 177, - "dropped": 248 + "ingested": 164, + "dropped": 261 }, "uk_obr_tables": { "read": 2807, - "ingested": 2712, - "dropped": 95 + "ingested": 2655, + "dropped": 152 }, "uk_rf_ab2026": { "read": 766, - "ingested": 574, - "dropped": 192 + "ingested": 547, + "dropped": 219 }, "uk_ifs_ab2026": { "read": 144, - "ingested": 12, - "dropped": 132 + "ingested": 11, + "dropped": 133 }, "uk_ippr": { "read": 3, @@ -40,13 +40,13 @@ }, "uk_centax": { "read": 112, - "ingested": 82, - "dropped": 30 + "ingested": 76, + "dropped": 36 }, "uk_tpa": { "read": 305, - "ingested": 189, - "dropped": 116 + "ingested": 179, + "dropped": 126 }, "uk_devolved_govts": { "read": 19, @@ -69,6 +69,7 @@ "categorical_rating_not_a_value": 7, "earlier_estimate_restated": 1, "energy_bill_level_no_metric": 35, + "figure_printed_again": 176, "hmt_figure_staged_twice": 432, "income_path_not_a_policy_effect": 9, "macro_fiscal_or_out_of_scope": 212, @@ -78,7 +79,7 @@ "parameter_or_threshold_level": 17, "partial_year_household_support": 3, "ratio_or_derived_quantity": 15, - "republished_twin_merged": 6, + "republished_twin_merged": 4, "restated_obr_forecast": 6, "restated_official_figure": 450, "share_level_no_registered_metric": 17, diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_centax/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_centax/NOTES.md index a9ec0184f..9871b9a74 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_centax/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_centax/NOTES.md @@ -109,6 +109,7 @@ We propose these, with CenTax's own words: - p. 13: 17%→12%, 33%→36% and 37%→33%; - Conclusion: 40.5%, 60%, 43.9%, 61.5%, 47%, 20% and 23%; - in the Unicorn Relief PDF: CenTax's "almost £20 billion" restates the £19.7bn in the same footnote. +- At ingest we merge six rows into another printing of the same figure, and list them in the ingest's `REPEATED_PRINTINGS`. In section 3.2 of Taxes at the top, CenTax rounds two of Table 1's shares (rows 62 and 64, into rows 82 and 67) and bounds a third (row 65, into row 66). It also prints three figures in two documents each. It gives the £640m in Taxes at the top's key findings and on its reaction page (row 25, into row 1). In footnote 9 of the Unicorn Relief PDF it repeats the £19.7bn of Taxes at the top's key findings and the £14bn of its section 3.1 (rows 107 and 108, into rows 21 and 58). - Under README rule 8 we left out these figures, which set an option's or a measure's design and estimate nothing: - the reaction page's "marginal tax rate of 33.3%", the Pension Tax Allowance's £1-for-£3 withdrawal rate restated as a percentage, which we keep in the 53% row's conditions; - its "a 100% marginal tax rate" (the Carer's Allowance taper of £1 for every £1, restated); diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_costings/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_costings/NOTES.md index dff01dd44..4f224493b 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_costings/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_costings/NOTES.md @@ -218,6 +218,7 @@ We put a registry key on a `row_type: measure` row only when the key's title cov - **Line 45 (pp.43-52):** the ten components sum to 110, 290, 240, 2,140, 2,635, 3,360 against Table 6.1's 10, 100, 115, 1,980, 2,485, 3,160. Table 6.1 falls short by 100, 190, 125, 160, 150 and 200. - **Line 47 (pp.54-58):** the five components sum to -10, 10, 125, 65, 145, 235 against Table 6.1's 195, -125, 60, 75, 155, 240. The differences come to +205, -135, -65, +10, +10 and +5. - **Line 85 (p.94):** equal from 2029-30 to 2031-32. HM Treasury prints larger costs in Table 6.1 from 2026-27 to 2028-29: -355, -175, -140 against the note's -15, +70, +45. +- HM Treasury prints each of line 45's ten costings again in red book Table 6.3, with the same figures in all six years. At ingest we merge these 60 rows into the red book's claims, and list them in the ingest's `REPEATED_PRINTINGS`. - **Table 6.2:** p.58's "+£130m estimated in 2029-30 in cash terms" equals Table 6.2 line 9 (DWP Fraud and Error) for 2029-30. - **Lines without a costing note:** HM Treasury gives 22 Table 6.1 lines no note: 1, 4, 9, 20, 22, 23, 24, 25, 31, 32, 34, 35, 40, 41, 42, 43, 63, 64, 67, 73, 74 and 81. - In the introduction HM Treasury limits the document to "tax and annually managed expenditure (AME) policy decisions". diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_redbook/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_redbook/NOTES.md index 5277c662a..e2fc50292 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_redbook/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_hmt_redbook/NOTES.md @@ -143,7 +143,7 @@ We mark 257 rows `own` and 168 `restated` (OBR, ONS, IMF, DWP, DBT, the British - **Periods.** - We give fiscal-year figures `conditions.fy`, end-year `period` and `time_basis: fiscal_year`. - For a multi-year total, or an average over the forecast, we keep the whole horizon in `conditions.horizon`, put the row at its final fiscal year and never annualise it. We read "over the forecast" as 2026-27 to 2031-32, as HM Treasury dates it in paragraphs 1.20 and 1.40. - - Where HM Treasury prints a figure more than once, we keep a row for each printing (as in AB2025) and give the repeats one dating, the most specific mention's (review A's RB-15). Where more than two printings would share one claim identity, we keep only two (RB-2). + - Where HM Treasury prints a figure more than once, we keep a row for each printing (as in AB2025) and give the repeats one dating, the most specific mention's (review A's RB-15). Where more than two printings would share one claim identity, we keep only two (RB-2). At ingest we merge 14 of these repeats into one printing of the figure, and list them in the ingest's `REPEATED_PRINTINGS`: rows 5, 180, 181, 189, 190, 194, 197, 201, 202, 256, 265, 268, 362 and 423. Before we merge rows 5, 180 and 189, we give each the time basis of the printing we keep (`ROW_TIME_BASES`). Into Table 6.3's rows 273 to 332 we also merge the costings' printings of the ten tax-gap measures. - We put an undated figure ("by the late 2030s", "this winter") at the publication year 2026, with the printed horizon in conditions and, where the year matters, `parse_confidence: medium`. - **Geography.** We take it from the harvest's closed list (`UK`, `GB`, `England`, `Wales`, `Scotland`, `Northern Ireland`, `England and Wales`, `Scotland, Wales and Northern Ireland`), and put any detail in `conditions.geography_note` or `note`. We record the Ofgem price cap and BICS as `GB`. - **Prices.** HM Treasury prints every money figure in cash, and we stage it so; on Table 1.3's rows we set `price_basis: current prices`. We convert no basis. (Our first staging tagged the £595 million administration saving `real terms`. But in paragraph 2.14 HM Treasury applies "real terms" to the Spending Review's 16% cut, and the £595 million equals Table 6.1 line 63's cash +595.) diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_ifs_ab2026/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_ifs_ab2026/NOTES.md index 8e153304b..62966ebd3 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_ifs_ab2026/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_ifs_ab2026/NOTES.md @@ -101,7 +101,7 @@ The opening remarks (rows 92 to 97; we saved the whole speech on line 6 of the t - £17 billion: proposed metric `spending_pressure`, IFS's estimate of the top-up that avoiding real-terms cuts could need. IFS prints its year as "2030-21", a typo, most likely for 2030–31. We keep "2030-21" in the quote and `conditions.horizon`, set no `fy`, use 2026 as a publication-year marker and give the row medium confidence. - £11 billion: `spending_pressure` for defence plans, on top of the £17 billion. IFS prints no year on the page; on Boileau slide 4 it prints £11 billion more defence spending in 2030–31 (row 55). We give the row medium confidence and a 2026 marker. - 25% and 40%: proposed metric `reserve_allocated_share`, the shares of the capital and day-to-day reserves already spent, restated `administrative_fact`. IFS names a source neither in the remarks nor on Boileau slide 11, where it prints the same two shares. So in all four rows we infer the restated attribution and give medium confidence. -- 80%: `affected_share` 0.8 of households, for the £100 payment through council tax bands A-D, keyed to `ab2026__household_energy_payment_100_bands_a_to_d`. +- 80%: `affected_share` 0.8 of households, for the £100 payment through council tax bands A-D, keyed to `ab2026__household_energy_payment_100_bands_a_to_d`. IFS gives the same estimate in its initial response, on line 28 (row 91), so at ingest we merge this row into that one and list it in the ingest's `REPEATED_PRINTINGS`. ### The seven visualisations (46 rows) diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_obr_tables/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_obr_tables/NOTES.md index ddaddc44e..237266832 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_obr_tables/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_obr_tables/NOTES.md @@ -236,7 +236,7 @@ We leave every `baseline_policy` null, and give effect estimates the explicit un - Guarantee capacity, a contingent liability: UK Export Finance's £40bn and the Growth Guarantee Scheme's £7bn (para 3.21). - A lending allocation: Your First Home's £0.7bn and £1bn of loans (para 3.22). We stage paragraph 3.22's effect on debt (£0.7bn in the first year). - **The rule for lending and financing (4 November, the coordinator's call on review B's finding 5; README rule 8).** In the harvest we stage HM Treasury's Tables 6.1, 6.2 and 6.4 and the OBR's policy workbook whole, as the decisions' costings. Elsewhere we treat an amount a scheme will lend or spend as design (rule 8), and an effect on borrowing, debt or the financing requirement as an estimate. So we keep paragraph 3.22's loan volumes dropped and its effect on debt staged. We had dropped paragraph 3.20's "£1.9 billion a year" increase in the Government's financing requirement on 3 November as a financing allocation, and we restored it as a fiscal-aggregate estimate (`cash_requirement_change`). In EFO paragraphs 6.19–6.20 the OBR says the CGNCR "forms the basis of" the DMO's remit, so we treat the requirement as the aggregate and the remit as the design. -- **Repeats, which we dropped on 3 November (review finding 5, the coordinator's call): 37 rows.** As in the AB2025 OBR family, we stage the table cells. We dropped text that repeats a Table 3.1 cell (paras 3.2, 3.3, 3.4, 3.11, 3.13, 3.16, 3.17 and 3.19: 19 rows) or earlier text (paras 3.11, 3.12, 3.13 and 3.16: 6 rows). We also dropped Table 3.1's "Spending measures" and "Tax measures" rows, which repeat its "Direct effect of spending measures" and "Direct effect of tax measures" rows (12 rows). +- **Repeats, which we dropped on 3 November (review finding 5, the coordinator's call): 37 rows.** As in the AB2025 OBR family, we stage the table cells. We dropped text that repeats a Table 3.1 cell (paras 3.2, 3.3, 3.4, 3.11, 3.13, 3.16, 3.17 and 3.19: 19 rows) or earlier text (paras 3.11, 3.12, 3.13 and 3.16: 6 rows). We also dropped Table 3.1's "Spending measures" and "Tax measures" rows, which repeat its "Direct effect of spending measures" and "Direct effect of tax measures" rows (12 rows). At ingest we also merge 57 rows into another printing of the same figure, and list them in the ingest's `REPEATED_PRINTINGS`. The OBR rounds six of the policy workbook's Table 1.1 totals in paragraphs 3.3, 3.4, 3.16 and 3.18 (rows 2526, 2531, 2667, 2672, 2673 and 2674). It rounds two more Table 1.1 lines, the direct effect of Government decisions and measure 2's VAT, in paragraphs 3.2 and 3.19 (rows 2520, 2680 and 2681), and a Table 3.1 line in paragraph 3.11 (row 2655). It prints seven lines of Table 3.1 again in Table 1.1, each from 2026-27 to 2031-32 (rows 2540–2545, 2552–2569, 2576–2581 and 2630–2641), and the online marketplace measure's yield in both Table 3.3 and Table 1.1 (rows 2712–2716). - **Other estimates in chapters 1, 2 and 4–6 and paragraph 7.20 (4 November, review B finding 4; the coordinator's call).** In most of these chapters the OBR repeats Table 3.1 and the workbook's lines by head (Tables 4.5–4.7, 5.4, 5.6 and 6.2 among them). The OBR gives these new estimates there, which we didn't stage; tranche 2 may add any of them as components: - Tables 4.2 (p.87, indirect effects on receipts), 5.2 (p.108, indirect effects on spending) and 5.8 (p.128, "Effects of Government decisions" on debt interest, −0.9 / 1.2 / 1.0 / 0.7 / 0.4 / 0.3). They form parts of the decisions' total effect, which we stage whole in rows 2490–2495 and 2534–2539 (4f424b9 order). @@ -372,10 +372,10 @@ On 6 November we moved rows 2740 and 2800 to the OBR's forecast on the latest policy. In paragraph 4.30 the OBR forecasts fuel duty receipts on the assumption that the government carries out its latest policy: it freezes the duty until July 2027 and raises it from then. Against that -forecast, the OBR estimates that keeping the freeze would add £4.3 -billion to borrowing in 2029-30 (paragraph 3.43) and cut receipts by £4 -billion a year on average from 2027-28 to 2031-32 (paragraph 4.30). So we -propose that world for both rows, and the ingest maps it to +forecast, the OBR estimates that if the government kept the freeze, it +would borrow £4.3 billion more in 2029-30 (paragraph 3.43) and collect £4 +billion less a year on average from 2027-28 to 2031-32 (paragraph 4.30). +So we propose that world for both rows, and the ingest maps it to `obr_october_2026_budget_forecast__policy_parameters`. The stager also reproduces tranche 2's 535 key registrations, and diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_rf_ab2026/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_rf_ab2026/NOTES.md index 94ae1a7ed..30bb174b8 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_rf_ab2026/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_rf_ab2026/NOTES.md @@ -76,7 +76,7 @@ Under "Not staged" below we list the 36 design rows we removed under rule 8 and - **Text.** We stage every number RF prints that estimates, forecasts or counts the effect of the Budget's measures or of the Budget as a whole. That covers costs and yields, households affected, gains and losses, bill changes, distributional and poverty effects, and the public finances after the Budget. - We also stage, as `measure_key: null` context, the living-standards and poverty projections and the energy-bill context that the cost-of-living measures address. - Where RF prints a number twice with the same meaning in one document, we stage one row, at the occurrence where RF states its period or scope most completely. For example, RF dates the £2,192 cap level Q1 2027 on p.16 and calls it "next year" on p.5, so we cite p.16 in the row. - - Where a producer states the same figure in different documents, we stage each (the AB2025 precedent). At ingest we merge rows 26, 27, 60, 132 and 201 into the claim of another printing of the same RF figure. + - Where a producer states the same figure in different documents, we stage each (the AB2025 precedent). At ingest we merge rows 26, 27, 132 and 201 into the claim of another printing of the same RF figure. We also merge 28 rows into the printing we keep, and list them in the ingest's `REPEATED_PRINTINGS`. In nine, RF prints a figure again in another document (rows 41, 54, 61, 63, 93, 127, 133, 153 and 177). In five, it bounds a figure it gives elsewhere (28, 29, 48, 58 and 137), and in fourteen it rounds a value that it gives in full in its chart workbook (59, 60, 77, 138, 147–151, 198, 200, 205, 208 and 209). - **Workbook.** We stage the chart data behind the figures in which RF gives its own estimates. - F7 (energy bill and support by year). - F8 (temporary AB26 policies by vigintile). diff --git a/sources/harvest-uk-ab2026-2026-10-29/uk_tpa/NOTES.md b/sources/harvest-uk-ab2026-2026-10-29/uk_tpa/NOTES.md index af2615c94..051bfbe90 100644 --- a/sources/harvest-uk-ab2026-2026-10-29/uk_tpa/NOTES.md +++ b/sources/harvest-uk-ab2026-2026-10-29/uk_tpa/NOTES.md @@ -192,8 +192,8 @@ We use the registered metrics `revenue_change`, `caseload` and, for the totals o In its review (`harvest-staging/ab2026/reviews/verify-thinktanks-a.md` on the staging branch), the thinktanks-a reviewer approved this family with fixes. We put each in an explicit block at the end of `stage.py`'s rows. We re-opened no primary, because the session's network policy refused taxpolicy.org.uk, and changed no printed value. - Finding 1, the coordinator's call: we dropped row 16, "£93", as the allowance's design under rule 8, and set `conditions.tax_removed: "£93 (as printed)"` on row 17 (53%). The 306 rows became 305. -- Finding 2: we made no change, since we had already set `conditions.derived_from` on the group, deflated and %-of-GDP rows. At ingest we copy the field onto each of the 155 claims these 186 rows become, and drop the other 31 (30 as out of scope, 1 as a ratio). No code reads the field, so separating these claims from model estimates stays open. -- Finding 3: we made no change. We stage the 2027-28 total tax policy decisions on rows 3, 26, 27, 147, 169 and 237 (0-based before the drop) and the six-year total on rows 4, 28 and 265. At ingest, counting today's 305 rows from 0, we drop the restated rows 3, 26, 146 and 236, and score rows 25 and 168 (2027-28) and 4, 27 and 264 (six years) on `decisions_effect_on_borrowing`. We merge none of these five at ingest, so their duplication stays open. +- Finding 2: we made no change, since we had already set `conditions.derived_from` on the group, deflated and %-of-GDP rows. At ingest we make claims from 145 of these 186 rows and copy the field onto each. Of the other 41, we drop 31 (30 as out of scope, 1 as a ratio) and merge 10 into another printing of the same figure (Finding 3). No code reads the field, so separating these claims from model estimates stays open. +- Finding 3: we made no change. We stage the 2027-28 total tax policy decisions on rows 3, 26, 27, 147, 169 and 237 (0-based before the drop) and the six-year total on rows 4, 28 and 265. At ingest, counting today's 305 rows from 0, we drop the restated rows 3, 26, 146 and 236, and score rows 25 and 168 (2027-28) and 4, 27 and 264 (six years) on `decisions_effect_on_borrowing`. Since 6 November we merge row 168 into row 25 at ingest, and rows 4 and 264 into row 27, so we score each total once. We merge seven more TPA repeats the same way, and list all ten in the ingest's `REPEATED_PRINTINGS`. TPA rounds row 6's £1.1bn to "about £1bn" on row 8 and row 104's £5.9bn to "about £6bn" on row 2, and gives five groups' 2027/28 values in two charts (rows 176, 194, 206, 212 and 224). - Finding 4: we now say, in the quote convention above, that we re-serialise JSON elements. - Finding 5 (optional, applied): on row 1 ("About two-fifths") we use `proposed_metric: revenue_share_by_fiscal_event`, not the registered `revenue_share`. - Finding 6: we added the registry caveat to the two by-tax scopes in the group-key table. diff --git a/tests/test_uk_ab2026_ingest.py b/tests/test_uk_ab2026_ingest.py index 8cba9e3d3..d26dd3ef7 100644 --- a/tests/test_uk_ab2026_ingest.py +++ b/tests/test_uk_ab2026_ingest.py @@ -19,10 +19,13 @@ """ import copy +import functools import gzip import json +import math import os import random +import re import shutil import sqlite3 import subprocess @@ -32,12 +35,12 @@ from types import SimpleNamespace import pytest -from hypothesis import HealthCheck, given, settings +from hypothesis import HealthCheck, example, given, settings from hypothesis import strategies as st from scorecard_db import ScorecardDB, signs from scorecard_db import ingest_uk_ab2026 as I -from scorecard_db.models import Metric +from scorecard_db.models import Metric, ReformRef, TimeBasis, UnitConcept from scorecard_db.uk_aliases import canon, known ROOT = Path(__file__).resolve().parent.parent @@ -181,6 +184,51 @@ def test_a_moved_row_call_raises(monkeypatch): I._check_row_calls("uk_obr_tables", RAW["uk_obr_tables"]) +def test_a_moved_time_basis_call_raises(monkeypatch): + monkeypatch.setitem( + I.ROW_TIME_BASES, + ("uk_hmt_redbook", 0), + ("annual", "not this value", "point_in_time", "x" * 41), + ) + with pytest.raises(ValueError, match="no longer matches"): + I._check_row_calls("uk_hmt_redbook", RAW["uk_hmt_redbook"]) + + +def test_each_restaged_row_takes_the_time_basis_we_store(): + """We stage HM Treasury's £50 off the annual price + cap, and its count of households that the government pays from January + 2027, on the time basis of the printing we keep.""" + assert len(I.ROW_TIME_BASES) == 3 + for (family, i), (staged, printed, stored, why) in I.ROW_TIME_BASES.items(): + assert (RAW[family][i]["time_basis"], RAW[family][i]["value_raw"]) == ( + staged, + printed, + ) + assert _staged_alone(family, i).time_basis.value == stored, (family, i) + assert len(why) > 40 + + +@pytest.mark.parametrize( + "family, i, field, value, table", + [ + ("uk_hmt_redbook", 5, "time_basis", "annual", "ROW_TIME_BASES"), + ("uk_hmt_redbook", 5, "value_raw", "around £60", "ROW_TIME_BASES"), + ("uk_ifs_ab2026", 46, "proposed_metric", "another_metric", "ROW_METRICS"), + ("uk_ifs_ab2026", 46, "value_raw", "£90", "ROW_METRICS"), + ], +) +def test_a_row_call_raises_when_either_of_its_fields_moves( + family, i, field, value, table +): + """On a row we restage, we change one of the two fields + that the ingest checks and leave the other, and the ingest raises on + each.""" + rows = list(RAW[family]) + rows[i] = {**rows[i], field: value} + with pytest.raises(ValueError, match=f"{table} {family} row {i} no longer"): + I._check_row_calls(family, rows) + + # --- 2. keys and verdicts ---------------------------------------------------- @@ -235,10 +283,14 @@ def test_each_hm_treasury_figure_is_counted_once(staged): acct["by_family"]["uk_hmt_costings"]["drops"]["hmt_figure_staged_twice"] == 408 ) assert acct["by_family"]["uk_hmt_redbook"]["drops"]["hmt_figure_staged_twice"] == 24 - printed = [s for s in scores if "also_printed_in" in s.publication] + printed = [ + s + for s in scores + if s.publication["family"] == "uk_hmt_tables" + and "also_printed_in" in s.publication + ] assert sum(len(s.publication["also_printed_in"]) for s in printed) == 432 for s in printed: - assert s.publication["family"] == "uk_hmt_tables" assert { t["family"] for t in s.publication["also_printed_in"] } <= I._TWIN_FAMILIES @@ -336,6 +388,1013 @@ def test_no_costings_or_red_book_claim_repeats_a_table_figure(staged): assert all(len(why) > 40 for why in NOT_TWINS.values()) +# --- figures a producer prints more than once ---------------------------------- + +# Each repeated printing, the printing whose claim we keep, and the value_raw +# of both, which we list here apart from I.REPEATED_PRINTINGS: +# (family, repeat row) -> (kept row, repeat's printing, kept printing). We +# give the kept row as (family, row) where its family differs. +REPEATED_PINS = { + ("uk_centax", 25): (1, "£640 million", "£640 million"), + ("uk_centax", 62): (82, "58%", "57.52%"), + ("uk_centax", 64): (67, "9%", "8.75%"), + ("uk_centax", 65): (66, "less than 0.5%", "0.40%"), + ("uk_centax", 107): (21, "£19.7 billion", "£19.7 billion"), + ("uk_centax", 108): (58, "£14 billion", "£14 billion"), + ("uk_hmt_costings", 191): (("uk_hmt_redbook", 273), "+0m", "+0m"), + ("uk_hmt_costings", 192): (("uk_hmt_redbook", 274), "+10m", "+10m"), + ("uk_hmt_costings", 193): (("uk_hmt_redbook", 275), "+55m", "+55m"), + ("uk_hmt_costings", 194): (("uk_hmt_redbook", 276), "+140m", "+140m"), + ("uk_hmt_costings", 195): (("uk_hmt_redbook", 277), "+160m", "+160m"), + ("uk_hmt_costings", 196): (("uk_hmt_redbook", 278), "+150m", "+150m"), + ("uk_hmt_costings", 197): (("uk_hmt_redbook", 279), "+0m", "+0m"), + ("uk_hmt_costings", 198): (("uk_hmt_redbook", 280), "+0m", "+0m"), + ("uk_hmt_costings", 199): (("uk_hmt_redbook", 281), "-85m", "-85m"), + ("uk_hmt_costings", 200): (("uk_hmt_redbook", 282), "+70m", "+70m"), + ("uk_hmt_costings", 201): (("uk_hmt_redbook", 283), "+25m", "+25m"), + ("uk_hmt_costings", 202): (("uk_hmt_redbook", 284), "+25m", "+25m"), + ("uk_hmt_costings", 203): (("uk_hmt_redbook", 285), "+0m", "+0m"), + ("uk_hmt_costings", 204): (("uk_hmt_redbook", 286), "+0m", "+0m"), + ("uk_hmt_costings", 205): (("uk_hmt_redbook", 287), "+0m", "+0m"), + ("uk_hmt_costings", 206): (("uk_hmt_redbook", 288), "+1,355m", "+1,355m"), + ("uk_hmt_costings", 207): (("uk_hmt_redbook", 289), "+1,605m", "+1,605m"), + ("uk_hmt_costings", 208): (("uk_hmt_redbook", 290), "+1,815m", "+1,815m"), + ("uk_hmt_costings", 209): (("uk_hmt_redbook", 291), "+0m", "+0m"), + ("uk_hmt_costings", 210): (("uk_hmt_redbook", 292), "+0m", "+0m"), + ("uk_hmt_costings", 211): (("uk_hmt_redbook", 293), "+0m", "+0m"), + ("uk_hmt_costings", 212): (("uk_hmt_redbook", 294), "+165m", "+165m"), + ("uk_hmt_costings", 213): (("uk_hmt_redbook", 295), "+5m", "+5m"), + ("uk_hmt_costings", 214): (("uk_hmt_redbook", 296), "+5m", "+5m"), + ("uk_hmt_costings", 215): (("uk_hmt_redbook", 297), "+0m", "+0m"), + ("uk_hmt_costings", 216): (("uk_hmt_redbook", 298), "+0m", "+0m"), + ("uk_hmt_costings", 217): (("uk_hmt_redbook", 299), "+0m", "+0m"), + ("uk_hmt_costings", 218): (("uk_hmt_redbook", 300), "+20m", "+20m"), + ("uk_hmt_costings", 219): (("uk_hmt_redbook", 301), "+65m", "+65m"), + ("uk_hmt_costings", 220): (("uk_hmt_redbook", 302), "+55m", "+55m"), + ("uk_hmt_costings", 221): (("uk_hmt_redbook", 303), "+0m", "+0m"), + ("uk_hmt_costings", 222): (("uk_hmt_redbook", 304), "+0m", "+0m"), + ("uk_hmt_costings", 223): (("uk_hmt_redbook", 305), "+0m", "+0m"), + ("uk_hmt_costings", 224): (("uk_hmt_redbook", 306), "+50m", "+50m"), + ("uk_hmt_costings", 225): (("uk_hmt_redbook", 307), "+255m", "+255m"), + ("uk_hmt_costings", 226): (("uk_hmt_redbook", 308), "+320m", "+320m"), + ("uk_hmt_costings", 227): (("uk_hmt_redbook", 309), "+65m", "+65m"), + ("uk_hmt_costings", 228): (("uk_hmt_redbook", 310), "+120m", "+120m"), + ("uk_hmt_costings", 229): (("uk_hmt_redbook", 311), "+0m", "+0m"), + ("uk_hmt_costings", 230): (("uk_hmt_redbook", 312), "+75m", "+75m"), + ("uk_hmt_costings", 231): (("uk_hmt_redbook", 313), "+250m", "+250m"), + ("uk_hmt_costings", 232): (("uk_hmt_redbook", 314), "+575m", "+575m"), + ("uk_hmt_costings", 235): (("uk_hmt_redbook", 315), "+50m", "+50m"), + ("uk_hmt_costings", 236): (("uk_hmt_redbook", 316), "+205m", "+205m"), + ("uk_hmt_costings", 237): (("uk_hmt_redbook", 317), "+310m", "+310m"), + ("uk_hmt_costings", 238): (("uk_hmt_redbook", 318), "+260m", "+260m"), + ("uk_hmt_costings", 239): (("uk_hmt_redbook", 319), "+270m", "+270m"), + ("uk_hmt_costings", 240): (("uk_hmt_redbook", 320), "+415m", "+415m"), + ("uk_hmt_costings", 241): (("uk_hmt_redbook", 321), "+0m", "+0m"), + ("uk_hmt_costings", 242): (("uk_hmt_redbook", 322), "-15m", "-15m"), + ("uk_hmt_costings", 243): (("uk_hmt_redbook", 323), "-40m", "-40m"), + ("uk_hmt_costings", 244): (("uk_hmt_redbook", 324), "+5m", "+5m"), + ("uk_hmt_costings", 245): (("uk_hmt_redbook", 325), "+0m", "+0m"), + ("uk_hmt_costings", 246): (("uk_hmt_redbook", 326), "+0m", "+0m"), + ("uk_hmt_costings", 247): (("uk_hmt_redbook", 327), "-5m", "-5m"), + ("uk_hmt_costings", 248): (("uk_hmt_redbook", 328), "-30m", "-30m"), + ("uk_hmt_costings", 249): (("uk_hmt_redbook", 329), "+0m", "+0m"), + ("uk_hmt_costings", 250): (("uk_hmt_redbook", 330), "+0m", "+0m"), + ("uk_hmt_costings", 251): (("uk_hmt_redbook", 331), "+0m", "+0m"), + ("uk_hmt_costings", 252): (("uk_hmt_redbook", 332), "+0m", "+0m"), + ("uk_hmt_redbook", 5): (188, "around £50", "£50"), + ("uk_hmt_redbook", 180): (7, "20 million", "up to 20 million"), + ("uk_hmt_redbook", 181): (354, "£2.3 billion", "+2,250m"), + ("uk_hmt_redbook", 189): (7, "20 million", "up to 20 million"), + ("uk_hmt_redbook", 190): (188, "£50", "£50"), + ("uk_hmt_redbook", 194): (9, "£30", "around £30"), + ("uk_hmt_redbook", 197): (188, "£50", "£50"), + ("uk_hmt_redbook", 201): (9, "£30", "around £30"), + ("uk_hmt_redbook", 202): (187, "35 million", "35 million"), + ("uk_hmt_redbook", 256): (14, "70,000", "70,000"), + ("uk_hmt_redbook", 265): (176, "£50 million", "£50 million"), + ("uk_hmt_redbook", 268): (258, "£15 million", "£15 million"), + ("uk_hmt_redbook", 362): (400, "£33,500", "33,500"), + ("uk_hmt_redbook", 423): (422, "£166", "£166"), + ("uk_ifs_ab2026", 97): (91, "80%", "80%"), + ("uk_obr_tables", 2520): (2501, "£12 billion", "11,681"), + ("uk_obr_tables", 2526): (2171, "£5.5 billion", "5500"), + ("uk_obr_tables", 2531): (1183, "£1 billion", "951"), + ("uk_obr_tables", 2540): (2352, "5.8", "-5,848"), + ("uk_obr_tables", 2541): (2353, "3.9", "-3,877"), + ("uk_obr_tables", 2542): (2354, "3.5", "-3,458"), + ("uk_obr_tables", 2543): (2355, "1.7", "-1,699"), + ("uk_obr_tables", 2544): (2356, "1.6", "-1,578"), + ("uk_obr_tables", 2545): (2357, "-4.2", "4,161"), + ("uk_obr_tables", 2552): (2514, "-1.3", "-1,308"), + ("uk_obr_tables", 2553): (2515, "3.5", "3,483"), + ("uk_obr_tables", 2554): (2516, "1.7", "1,702"), + ("uk_obr_tables", 2555): (2517, "1.4", "1,424"), + ("uk_obr_tables", 2556): (2518, "1.4", "1,442"), + ("uk_obr_tables", 2557): (2519, "2.4", "2,412"), + ("uk_obr_tables", 2558): (2496, "7.6", "-7,597"), + ("uk_obr_tables", 2559): (2497, "3.5", "-3,532"), + ("uk_obr_tables", 2560): (2498, "0.4", "-380"), + ("uk_obr_tables", 2561): (2499, "-4.1", "4,061"), + ("uk_obr_tables", 2562): (2500, "-5.0", "4,983"), + ("uk_obr_tables", 2563): (2501, "-11.7", "11,681"), + ("uk_obr_tables", 2564): (6, "2.6", "-2627"), + ("uk_obr_tables", 2565): (7, "0.0", "0"), + ("uk_obr_tables", 2566): (8, "0.0", "0"), + ("uk_obr_tables", 2567): (9, "0.0", "0"), + ("uk_obr_tables", 2568): (10, "0.0", "0"), + ("uk_obr_tables", 2569): (11, "0.0", "0"), + ("uk_obr_tables", 2576): (2184, "0.0", "0"), + ("uk_obr_tables", 2577): (2185, "1.1", "-1058"), + ("uk_obr_tables", 2578): (2186, "1.1", "-1113"), + ("uk_obr_tables", 2579): (2187, "1.1", "-1132"), + ("uk_obr_tables", 2580): (2188, "1.2", "-1151"), + ("uk_obr_tables", 2581): (2189, "1.2", "-1169"), + ("uk_obr_tables", 2630): (2502, "7.6", "-7,597"), + ("uk_obr_tables", 2631): (2503, "2.5", "-2,475"), + ("uk_obr_tables", 2632): (2504, "-0.7", "732"), + ("uk_obr_tables", 2633): (2505, "-5.2", "5,192"), + ("uk_obr_tables", 2634): (2506, "-6.1", "6,134"), + ("uk_obr_tables", 2635): (2507, "-7.3", "7,349"), + ("uk_obr_tables", 2636): (2508, "0.0", "0"), + ("uk_obr_tables", 2637): (2509, "1.1", "-1,058"), + ("uk_obr_tables", 2638): (2510, "1.1", "-1,113"), + ("uk_obr_tables", 2639): (2511, "1.1", "-1,132"), + ("uk_obr_tables", 2640): (2512, "1.2", "-1,151"), + ("uk_obr_tables", 2641): (2513, "-4.3", "4,331"), + ("uk_obr_tables", 2655): (2570, "£5 billion", "5.4"), + ("uk_obr_tables", 2667): (1167, "£0.7 billion", "688"), + ("uk_obr_tables", 2672): (1005, "£0.8 billion", "802"), + ("uk_obr_tables", 2673): (1347, "£0.3 billion", "253"), + ("uk_obr_tables", 2674): (537, "£0.3 billion", "-261"), + ("uk_obr_tables", 2680): (18, "£0.7 billion", "-734"), + ("uk_obr_tables", 2681): (19, "£0.3 billion", "-296"), + ("uk_obr_tables", 2712): (943, "-164", "164"), + ("uk_obr_tables", 2713): (944, "-318", "318"), + ("uk_obr_tables", 2714): (945, "-270", "270"), + ("uk_obr_tables", 2715): (946, "-250", "250"), + ("uk_obr_tables", 2716): (947, "-264", "264"), + ("uk_rf_ab2026", 28): (74, "under £145", "£145"), + ("uk_rf_ab2026", 29): (76, "over £130", "£130"), + ("uk_rf_ab2026", 41): (49, "3 per cent", "3.0 per cent"), + ("uk_rf_ab2026", 48): (130, "just over half", "52 per cent"), + ("uk_rf_ab2026", 54): (34, "£4.4 billion", "£4.4 billion"), + ("uk_rf_ab2026", 58): (383, "over a million", "1572152"), + ("uk_rf_ab2026", 59): (379, "91 per cent", "0.90648359700588743"), + ("uk_rf_ab2026", 60): (765, "2.6 percentage points", "-2.6014506816864014"), + ("uk_rf_ab2026", 61): (56, "£158", "£158"), + ("uk_rf_ab2026", 63): (57, "£144", "£144"), + ("uk_rf_ab2026", 77): (382, "76 per cent", "0.76228673788146883"), + ("uk_rf_ab2026", 93): (47, "£3.7 billion", "£3.7 billion"), + ("uk_rf_ab2026", 127): (34, "£4.4 billion", "£4.4 billion"), + ("uk_rf_ab2026", 133): (4, "around one-in-eight", "around one-in-eight"), + ("uk_rf_ab2026", 137): (383, "over a million", "1572152"), + ("uk_rf_ab2026", 138): (379, "91 per cent", "0.90648359700588743"), + ("uk_rf_ab2026", 147): (433, "-£2.0bn", "-2.003759382381924"), + ("uk_rf_ab2026", 148): (434, "-£0.7bn", "-0.66114480370056317"), + ("uk_rf_ab2026", 149): (435, "+£1.5bn", "1.4700235532486525"), + ("uk_rf_ab2026", 150): (436, "+£1.9bn", "1.8860311488670831"), + ("uk_rf_ab2026", 151): (437, "+£2.7bn", "2.6523035758874194"), + ("uk_rf_ab2026", 153): (12, "around £20 billion", "around £20 billion"), + ("uk_rf_ab2026", 177): (13, "£2 billion", "£2 billion"), + ("uk_rf_ab2026", 198): (633, "1.8 per cent", "1.835872215777723E-2"), + ("uk_rf_ab2026", 200): (631, "5.0 per cent", "5.0346160874108259E-2"), + ("uk_rf_ab2026", 205): (765, "2.6 percentage points", "-2.6014506816864014"), + ("uk_rf_ab2026", 208): (763, "+0.8ppts", "0.83668380975723267"), + ("uk_rf_ab2026", 209): (764, "-0.4ppts", "-0.41938871145248413"), + ("uk_tpa", 2): (104, "about £6bn", "5.9"), + ("uk_tpa", 4): (27, "£19bn", "£19.1bn"), + ("uk_tpa", 8): (6, "about £1bn", "£1.1bn"), + ("uk_tpa", 168): (25, "£0.7bn", "£700m"), + ("uk_tpa", 176): (166, "-0.49", "-0.49"), + ("uk_tpa", 194): (163, "-0.29", "-0.29"), + ("uk_tpa", 206): (158, "0.38", "0.38"), + ("uk_tpa", 212): (160, "0.155", "0.155"), + ("uk_tpa", 224): (157, "0.63", "0.63"), + ("uk_tpa", 264): (27, "£19.1bn", "£19.1bn"), +} + + +def _kept_row(family, k): + return k if isinstance(k, tuple) else (family, k) + + +def test_each_repeated_printing_pairs_the_rows_we_read(): + assert set(I.REPEATED_PRINTINGS) == set(REPEATED_PINS) + for (family, i), (k, repeat, kept) in REPEATED_PINS.items(): + assert I.REPEATED_PRINTINGS[(family, i)][0] == k, (family, i) + assert len(I.REPEATED_PRINTINGS[(family, i)][1]) > 40, (family, i) + kept_family, kept_row = _kept_row(family, k) + assert RAW[family][i]["value_raw"] == repeat, (family, i) + assert RAW[kept_family][kept_row]["value_raw"] == kept, (family, i) + + +@pytest.mark.parametrize("entry", sorted(REPEATED_PINS)) +def test_a_repeated_printing_merges_into_the_printing_we_keep(entry): + family, i = entry + k, repeat, kept = REPEATED_PINS[entry] + kept_family, kept_row = _kept_row(family, k) + families = {family: [(i, RAW[family][i])]} + families.setdefault(kept_family, []).append((kept_row, RAW[kept_family][kept_row])) + [claim], acct = I.stage(families) + assert (acct["read"], acct["ingested"], acct["dropped"]) == (2, 1, 1) + assert acct["drops"]["figure_printed_again"]["rows"] == 1 + assert acct["by_family"][family]["drops"]["figure_printed_again"] == 1 + assert claim.publication["family"] == kept_family + assert claim.conditions["value_verbatim"] == kept + assert ( + claim.publication["locator"] + == RAW[kept_family][kept_row]["publication"]["locator"] + ) + row = RAW[family][i] + assert claim.publication["also_printed_in"] == [ + { + "family": family, + "table": row.get("source_table"), + "locator": row["publication"].get("locator"), + "source_column": row.get("source_column") or None, + "value_verbatim": repeat, + } + ] + + +def test_each_repeated_printing_leaves_one_claim(staged): + """The full ingest drops each repeat once, in the repeat's family, and + lists it on the claim it keeps. On HM Treasury's table claims it lists only + their costings and red book twins, so we leave those claims out.""" + scores, acct = staged + assert acct["drops"]["figure_printed_again"]["rows"] == len(REPEATED_PINS) == 176 + for family, n in Counter(f for f, _ in REPEATED_PINS).items(): + assert acct["by_family"][family]["drops"]["figure_printed_again"] == n + listed = [ + (s.publication["family"], t["family"], t["value_verbatim"]) + for s in scores + if s.publication["family"] != "uk_hmt_tables" + for t in s.publication.get("also_printed_in", []) + ] + assert sorted(listed) == sorted( + (_kept_row(family, k)[0], family, repeat) + for (family, _), (k, repeat, _) in REPEATED_PINS.items() + ) + + +# Two claims that we pair in the scan below but keep apart: the (family, +# row) of each in the harvest -> why both stay claims. +_HMT_PACKAGE = ( + "HM Treasury costs two different measures of one package at the same amount " + "in this year, and we stage both under one reform key." +) +_OBR_TAX_GAP_ZERO = ( + "The OBR prints zero in this year for two different parts of the " + "government's package of measures to close the tax gap." +) + + +def _pairs(family, *rows): + return [((family, a), (family, b)) for a, b in rows] + + +NOT_REPEATS: dict[tuple[tuple[str, int], tuple[str, int]], str] = { + (("uk_centax", 90), ("uk_centax", 92)): ( + "CenTax estimates that the bottom 50% would pay 4% of the additional " + "revenue from taxing each of two kinds of income more: savings, and " + "other non-dividend investment income." + ), + (("uk_obr_tables", 875), ("uk_obr_tables", 2660)): ( + "In paragraph 3.13 the OBR costs the changes to HMRC's compliance " + "workforce, one part of the tax-gap package, at £0.4 billion in 2031-32. " + "In Table 1.1 it prints the whole package's onshore corporation tax, 445 " + "(£ million)." + ), + (("uk_obr_tables", 1357), ("uk_obr_tables", 2700)): ( + "Under the property income measure's tax head in Table 3.3, the OBR sums " + "the measure's receipts. In 2027-28 it prints zero on the measure's income " + "tax line in Table 1.1, so the sum equals the onshore corporation tax " + "line, 2 (£ million)." + ), + (("uk_tpa", 25), ("uk_tpa", 101)): ( + "In footnote 5 Tax Policy Associates sums HM Treasury's 2027-28 tax " + "costings to £700m in cash. On its chart of tax rises by fiscal event it " + "plots the OBR's costings in 2026 money, and puts that year's total at " + "£0.7bn too." + ), + **dict.fromkeys( + _pairs( + "uk_hmt_costings", + (126, 134), + (128, 136), + (259, 265), + (259, 284), + (263, 269), + (265, 284), + (267, 286), + (271, 277), + (340, 346), + (488, 494), + (489, 495), + (492, 498), + (493, 499), + ), + _HMT_PACKAGE, + ), + **dict.fromkeys( + _pairs( + "uk_obr_tables", + (852, 2594), + (853, 2595), + (853, 2706), + (888, 2594), + (900, 2594), + (914, 2596), + (2595, 2706), + ), + _OBR_TAX_GAP_ZERO, + ), +} + +_PRINTED = re.compile(r"(\d[\d,]*)(?:\.(\d+))?(?:[eE]([+-]?\d+))?") + + +def _last_digit(s): + """Return the place of a printing's last digit in claim units, which we + compute apart from I._printed_place. For a printing without digits, or a + value of zero, we return 0.""" + m = _PRINTED.search(s.conditions.get("value_verbatim") or "") + if not m or not s.value: + return 0.0 + number = float(m[1].replace(",", "") + "." + (m[2] or "0")) * 10 ** int(m[3] or 0) + if not number: + return 0.0 + return 10.0 ** (int(m[3] or 0) - len(m[2] or "")) * abs(s.value) / number + + +def _oriented(s): + relation, _ = signs.classify( + { + "metric": s.metric.value, + "conditions": s.conditions, + "country": "UK", + "source": s.source, + } + ) + if relation in (signs.SAME, signs.OPPOSITE): + return signs.external_value_pe_sign(s.value, relation) + return abs(s.value) + + +def _one_table(a, b): + """Whether the producer prints both claims in one table. We read two lines + of one table as two figures.""" + pa, pb = a.publication, b.publication + return ( + pa["family"] == pb["family"] + and pa.get("table") is not None + and pa.get("table") == pb.get("table") + ) + + +def _differ_in_scope(a, b): + """Whether two claims cover different places, housing cost bases, income + groups or averaging windows. We compare geography and housing costs where + we staged each condition for both printings, read a claim without an + income group as covering everyone, and read one without an aggregation as + a single year's figure.""" + ca, cb = a.conditions, b.conditions + if any( + k in ca and k in cb and ca[k] != cb[k] for k in ("geography", "housing_costs") + ): + return True + return (ca.get("income_group", "all"), ca.get("aggregation")) != ( + cb.get("income_group", "all"), + cb.get("aggregation"), + ) + + +def _part_of_measure(s): + """Whether the producer costs part of a measure in this printing, by the + scan's own reading, apart from the ingest's: we stage a component other + than the measure's total, or the row type of a measure component.""" + c = s.conditions + named = c.get("component") not in (None, "Total") + return named or c.get("row_type") == "measure_component" + + +def _repeats_in(scores): + """Pair claims by the scan's rule, each pair as the set of its two claim + ids.""" + groups: dict[tuple, list] = {} + for s in scores: + key = ( + s.source, + s.reform.key(), + s.metric, + s.unit_concept, + s.period, + s.time_basis, + s.period_start, + s.period_end, + _part_of_measure(s), + ) + groups.setdefault(key, []).append(s) + hits = set() + for group in groups.values(): + for x, a in enumerate(group): + for b in group[x + 1 :]: + if a.value is None or b.value is None: + continue + if _one_table(a, b) or _differ_in_scope(a, b): + continue + if ( + abs(_oriented(a) - _oriented(b)) + > max(_last_digit(a), _last_digit(b)) / 2 + 1e-9 + ): + continue + hits.add(frozenset((a.claim_id(), b.claim_id()))) + return hits + + +def _listed(): + """Map the two claim ids of each pair in NOT_REPEATS to its two rows.""" + listed = { + frozenset(_staged_alone(*row).claim_id() for row in pair): pair + for pair in NOT_REPEATS + } + assert all(len(ids) == 2 for ids in listed) and len(listed) == len(NOT_REPEATS) + return listed + + +def test_no_claim_repeats_another_printing_of_its_figure(staged): + """We pair the ingest's claims by a rule we wrote apart from + I.REPEATED_PRINTINGS. We treat two claims as one figure that the producer + prints twice when they share a source, reform, metric, unit, year, time + basis and window, and their values, zeros included, agree to half the + coarser printing's last digit. We also require that the producer cost part + of a measure in both, or the whole measure in both. We skip two lines of + one table and two claims that differ in scope, and for each other pair + that the ingest keeps, we give our reason in NOT_REPEATS under the two + claims' rows.""" + scores, _ = staged + listed = _listed() + where = { + s.claim_id(): (s.publication["family"], str(s.publication.get("locator"))) + for s in scores + } + hits = _repeats_in(scores) + assert hits == set(listed), ( + sorted(sorted(where[i] for i in ids) for ids in hits - set(listed)), + sorted(listed[ids] for ids in set(listed) - hits), + ) + assert all(len(why) > 40 for why in NOT_REPEATS.values()) + + +def test_the_scan_pairs_a_third_printing_with_both_listed_claims(staged): + """We add a third printing of CenTax row 90's 4% and + change one of its conditions, so it gets its own claim id. The scan pairs + it with rows 90 and 92, which NOT_REPEATS lists, and with no other claim.""" + scores, _ = staged + third = _claim("uk_centax", 90) + third.conditions["document_position"] = "a third printing" + ids = [_staged_alone("uk_centax", i).claim_id() for i in (90, 92)] + assert third.claim_id() not in ids + assert _repeats_in([*scores, third]) - set(_listed()) == { + frozenset((third.claim_id(), i)) for i in ids + } + + +def test_the_scan_reads_a_part_from_its_component_alone(staged): + """We add a third printing of CenTax row 90's 4%, + keep row 90's named component and stage it with the row type of a whole + measure. The scan reads it as part of the measure from its component, + and pairs it with rows 90 and 92.""" + scores, _ = staged + third = _claim("uk_centax", 90) + assert third.conditions["component"] not in (None, "Total") + third.conditions["row_type"] = "measure_total" + third.conditions["document_position"] = "a third printing" + ids = [_staged_alone("uk_centax", i).claim_id() for i in (90, 92)] + assert third.claim_id() not in ids + assert _repeats_in([*scores, third]) - set(_listed()) == { + frozenset((third.claim_id(), i)) for i in ids + } + + +@pytest.mark.parametrize( + "marks", + [{"component": None}, {"component": "Total"}, {"row_type": None}], + ids=["no component", "the total", "no row type"], +) +def test_the_scan_reads_a_part_from_either_marker(staged, marks): + """We add a third printing of CenTax row 90's 4%, which marks a part of + the measure by its named component and by its row type, and take one + marker away: we drop the component, name the measure's total in its + place, or drop the row type. The scan reads the part from the other + marker, and pairs the printing with rows 90 and 92 alone.""" + scores, _ = staged + third = _claim("uk_centax", 90) + c = third.conditions + assert c["component"] not in (None, "Total") + assert c["row_type"] == "measure_component" + for key, value in marks.items(): + if value is None: + del c[key] + else: + c[key] = value + c["document_position"] = "a third printing" + ids = [_staged_alone("uk_centax", i).claim_id() for i in (90, 92)] + assert third.claim_id() not in ids + assert _repeats_in([*scores, third]) - set(_listed()) == { + frozenset((third.claim_id(), i)) for i in ids + } + + +def test_the_merge_never_leaves_a_same_claim_twin(monkeypatch): + """RF prints row 60's figure again on row 205. Without row 60's entry, the + ingest would merge row 205 into row 765 and keep row 60, whose claim + shares row 205's id, so it raises.""" + monkeypatch.delitem(I.REPEATED_PRINTINGS, ("uk_rf_ab2026", 60)) + rows = [(i, RAW["uk_rf_ab2026"][i]) for i in (60, 205, 765)] + with pytest.raises(ValueError, match="shares its id with a repeat we dropped"): + I.stage({"uk_rf_ab2026": rows}) + + +def test_a_repeat_that_shares_its_kept_claim_s_id_merges(): + """If we staged row 25 with row 1's conditions, the + two claims would share an id. The ingest merges row 25 into row 1 and + keeps that one claim, so the twin guard lets it through.""" + rows = {i: copy.deepcopy(RAW["uk_centax"][i]) for i in (1, 25)} + rows[25]["conditions"] = copy.deepcopy(rows[1]["conditions"]) + [claim], acct = I.stage({"uk_centax": sorted(rows.items())}) + assert acct["drops"]["figure_printed_again"]["rows"] == 1 + assert claim.publication["locator"] == rows[1]["publication"]["locator"] + + +def test_a_full_ingest_raises_when_a_printing_goes_missing(monkeypatch): + monkeypatch.setitem(I.REPEATED_PRINTINGS, ("uk_tpa", 999_999), (27, "x" * 41)) + with pytest.raises(ValueError, match="uk_tpa row 999999 or its kept row 27"): + I.stage() + + +@functools.cache +def _staged_alone(family, i): + [s], _ = I.stage({family: [(i, RAW[family][i])]}) + return s + + +def _claim(family, i): + return copy.deepcopy(_staged_alone(family, i)) + + +# RF's fuel freeze path for 2027-28, which RF rounds on its chart's label and +# gives in full in its workbook. +FREEZE_LABEL = ("uk_rf_ab2026", 147) +FREEZE_CELL = ("uk_rf_ab2026", 433) + + +def _printing(s, printed, value): + s = copy.deepcopy(s) + s.conditions["value_verbatim"] = printed + s.value = float(value) + return s + + +@settings(max_examples=300, deadline=None) +@given( + cell=st.integers(-9_999_999, 9_999_999).filter(bool), + label=st.integers(-99, 99).filter(bool), +) +@example(cell=100_000, label=1) +@example(cell=150_000, label=1) +@example(cell=150_001, label=1) +@example(cell=-100_000, label=1) +def test_a_rounded_printing_agrees_only_to_half_its_last_digit(cell, label): + """We print the cell in £bn to six places (cell / 10**6) and the label to + one (label / 10). The ingest accepts the pair exactly when they differ by + at most £50 million. In the first example we print £0.1 billion in both + places, so only the precision check stops us keeping the label. In the + second, the two values differ by exactly £50 million, and in the third by + £1,000 more. In the fourth, they match in size and differ in sign.""" + label_claim, cell_claim = _claim(*FREEZE_LABEL), _claim(*FREEZE_CELL) + kept = _printing(cell_claim, f"{cell / 10**6:.6f}", cell * 1_000) + repeat = _printing(label_claim, f"£{abs(label) / 10:.1f}bn", label * 100_000_000) + agree = abs(cell * 1_000 - label * 100_000_000) <= 50_000_000 + if agree: + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + else: + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + # we never keep the coarser printing + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_rf_ab2026", 147, kept, repeat) + + +@pytest.mark.parametrize( + "change", + [ + lambda s: setattr(s, "source", "another_producer"), + lambda s: setattr(s, "reform", ReformRef("policy_ref", {"policy": "another"})), + lambda s: setattr(s, "metric", Metric.POVERTY_RATE_CHANGE), + lambda s: setattr(s, "unit_concept", UnitConcept.PERSONS), + lambda s: setattr(s, "period", s.period + 1), + lambda s: setattr(s, "time_basis", TimeBasis.POINT_IN_TIME), + lambda s: setattr(s, "period_start", s.period - 1), + lambda s: setattr(s, "period_end", s.period + 1), + lambda s: s.conditions.update(row_type="measure_component"), + lambda s: s.conditions.update(estimate_kind="range_high"), + lambda s: s.conditions.update(estimate_kind="cumulative"), + ], + ids=[ + "source", + "reform", + "metric", + "unit", + "year", + "time_basis", + "window_start", + "window_end", + "part_of_a_measure", + "kept_bound", + "estimate_kind", + ], +) +def test_a_printing_of_another_figure_raises(change): + """We change one field of the workbook's claim for RF's 2027-28 fuel + freeze path, which RF also labels on its chart. After each change we read + the claim as another figure, so the ingest raises.""" + repeat, kept = _claim(*FREEZE_LABEL), _claim(*FREEZE_CELL) + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + change(kept) + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + + +# We name here, apart from I._PER_PRINTING, the conditions that the printing +# check leaves out, so that adding one to I._PER_PRINTING fails a test. +PER_PRINTING = frozenset( + { + "chart_label", + "costing_leg_heading", + "document_position", + "document_version", + "estimate_kind", + "heading", + "paragraph_heading", + "reform_hint", + "sheet_section", + "sign_convention", + "table", + "table_line", + "table_row", + "value_verbatim", + } +) + + +def test_the_printing_check_leaves_out_the_conditions_we_name(): + assert I._PER_PRINTING == PER_PRINTING + + +def _compared(repeat, kept): + """Map each condition outside PER_PRINTING on which the two claims differ + to their two wordings, reading I._UNSTATED for a missing one.""" + keys = ( + repeat.conditions.keys() | kept.conditions.keys() | I._UNSTATED.keys() + ) - PER_PRINTING + first, second = ( + {k: s.conditions.get(k, I._UNSTATED.get(k)) for k in keys} + for s in (repeat, kept) + ) + return {k: (first[k], second[k]) for k in keys if first[k] != second[k]} + + +@pytest.mark.parametrize("side", ["repeat", "kept"]) +def test_a_printing_that_differs_in_any_compared_condition_raises( + staged, side, monkeypatch +): + """We give each condition that the check compares a + wording we don't list, on RF's chart label for the 2027-28 fuel freeze + path or on its workbook cell, and the ingest raises. When we also list the + wording for that repeat, the ingest accepts the pair. For the component, we + also name a part on the other printing, so the ingest reads both as parts + of the measure and compares the two parts we name.""" + scores, _ = staged + keys = ( + set(I._UNSTATED).union( + *(s.conditions for s in scores), + *(_staged_alone(*row).conditions for row in I.REPEATED_PRINTINGS), + ) + - PER_PRINTING + ) + assert len(keys) > 80 + listed = I._SAME_READING + missed, refused = [], [] + for key in sorted(keys): + repeat, kept = _claim(*FREEZE_LABEL), _claim(*FREEZE_CELL) + if key == "component": + (kept if side == "repeat" else repeat).conditions[key] = "a part we name" + (repeat if side == "repeat" else kept).conditions[key] = ( + "a wording we don't list" + ) + try: + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + missed.append(key) + except ValueError as e: + assert "no longer matches" in str(e) + [(a, b)] = _compared(repeat, kept).values() + monkeypatch.setattr(I, "_SAME_READING", listed | {(*FREEZE_LABEL, key, a, b)}) + try: + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + except ValueError: + refused.append(key) + monkeypatch.setattr(I, "_SAME_READING", listed) + assert (missed, refused) == ([], []) + + +@pytest.mark.parametrize( + "mark", + [{"component": "a part we name"}, {"row_type": "measure_component"}], + ids=["component", "row_type"], +) +def test_a_listed_wording_never_merges_a_part_into_the_whole(mark, monkeypatch): + """We stage RF's workbook cell for the 2027-28 fuel freeze path as part of + the measure, with a component we name or by its row type, and list both + wordings for its chart label. The ingest raises, since it never merges a + part of a measure into the whole, whatever wordings we list.""" + repeat, kept = _claim(*FREEZE_LABEL), _claim(*FREEZE_CELL) + kept.conditions.update(mark) + [(key, (a, b))] = _compared(repeat, kept).items() + assert key in mark + monkeypatch.setattr( + I, "_SAME_READING", I._SAME_READING | {(*FREEZE_LABEL, key, a, b)} + ) + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + + +@pytest.mark.parametrize( + "family, i, j, change, differ", + [ + ("uk_tpa", 274, 284, {}, {"tax_component"}), + ("uk_tpa", 287, 288, {}, {"country", "scenario"}), + ( + "uk_hmt_redbook", + 362, + 400, + {"household_type": "1 adult"}, + {"household_type", "statistic"}, + ), + ("uk_rf_ab2026", 147, 433, {"subgroup": "first-time buyers"}, {"subgroup"}), + ], + ids=["tax_component", "scenario", "household_type", "subgroup"], +) +def test_a_printing_for_another_part_scenario_or_group_raises( + family, i, j, change, differ, monkeypatch +): + """TPA puts a notional investment bank's tax in + Singapore at 14.9% of its profit, in total and from corporate income taxes + alone. It puts the bank's UK bank levies and deposit insurance at 2.3% of + profit before and after the Budget. We also change the household type of + HM Treasury's Table 2.C cell from two adults to one, and give RF's fuel + freeze cell a subgroup of first-time buyers. The ingest accepts each pair + once we list its wordings, and raises without them.""" + repeat, kept = _claim(family, i), _claim(family, j) + kept.conditions.update(change) + compared = _compared(repeat, kept) + assert set(compared) == differ + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing(family, i, repeat, kept) + monkeypatch.setattr( + I, + "_SAME_READING", + I._SAME_READING | {(family, i, k, *w) for k, w in compared.items()}, + ) + I._check_printing(family, i, repeat, kept) + + +def test_we_list_each_wording_for_the_repeat_that_uses_it(): + """We list in ``_SAME_READING`` each wording on which a repeat and the claim + we keep differ, under that repeat's row, and no other, so the ingest can't + use a stale listing to merge another figure.""" + used = set() + for (family, i), (k, _) in I.REPEATED_PRINTINGS.items(): + repeat, kept = _claim(family, i), _claim(*_kept_row(family, k)) + used |= {(family, i, key, *w) for key, w in _compared(repeat, kept).items()} + assert used == I._SAME_READING + + +# Each bound a producer prints, the point value we keep for it, and a +# printing of that point outside the bound: (family, bound row, point row) -> +# (printed, value) +OUTSIDE_THE_BOUND = { + ("uk_rf_ab2026", 28, 74): ("£146", 146), # under £145 + ("uk_rf_ab2026", 29, 76): ("£129", 129), # over £130 + ("uk_rf_ab2026", 48, 130): ("49 per cent", 0.49), # just over half + ("uk_rf_ab2026", 58, 383): ("999000", 999_000), # over a million + ("uk_centax", 65, 66): ("0.60%", 0.006), # less than 0.5% +} + + +@pytest.mark.parametrize("entry", sorted(OUTSIDE_THE_BOUND)) +def test_a_bound_merges_only_into_a_point_value_within_it(entry): + """We keep the point value, and the ingest raises if + it lies more than half its last digit past the bound.""" + family, i, k = entry + bound, point = _claim(family, i), _claim(family, k) + assert bound.conditions["estimate_kind"] in ("range_low", "range_high") + assert point.conditions.get("estimate_kind") not in ("range_low", "range_high") + I._check_printing(family, i, bound, point) + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing(family, i, bound, _printing(point, *OUTSIDE_THE_BOUND[entry])) + + +@pytest.mark.parametrize( + "entry, inside, outside", + [ + ( + ("uk_rf_ab2026", 48, 130), + ("over 52.4 per cent", 0.524), + ("over 52.6 per cent", 0.526), + ), + (("uk_rf_ab2026", 28, 74), ("under £144.6", 144.6), ("under £144.4", 144.4)), + ], +) +def test_a_point_value_agrees_with_a_bound_its_rounding_could_meet( + entry, inside, outside +): + """RF prints 52 per cent, which stands for any share from 51.5 to 52.5 + per cent, so it agrees with a bound of over 52.4 per cent but not with + one of over 52.6 per cent. In the same way £145 agrees with a bound of + under £144.6 but not with one of under £144.4.""" + family, i, k = entry + bound, point = _claim(family, i), _claim(family, k) + I._check_printing(family, i, _printing(bound, *inside), point) + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing(family, i, _printing(bound, *outside), point) + + +@pytest.mark.parametrize( + "entry, bound_printing, point_printing", + [ + (("uk_rf_ab2026", 48, 130), ("over 3.5 per cent", 0.035), ("3 per cent", 0.03)), + (("uk_centax", 65, 66), ("less than 4.5%", 0.045), ("5%", 0.05)), + ], +) +def test_a_point_half_its_last_digit_past_a_bound_agrees( + entry, bound_printing, point_printing +): + """A producer could print 3 per cent for any share up to 3.5 per cent, so + that printing agrees with a bound of over 3.5 per cent. In the same way, 5% + agrees with a bound of less than 4.5%. In binary floating point, 0.03 + 0.005 + falls short of 0.035 and 0.05 - 0.005 exceeds 0.045, so the ingest allows a + few units in the last place here too.""" + family, i, k = entry + bound = _printing(_claim(family, i), *bound_printing) + point = _printing(_claim(family, k), *point_printing) + I._check_printing(family, i, bound, point) + + +def test_a_bound_and_a_point_of_opposite_signs_raise(): + """RF bounds a typical household's gain under £145 and gives £145 in + another printing. If RF printed the second as a loss, we could no longer + read the bound against it.""" + bound, point = _claim("uk_rf_ab2026", 28), _claim("uk_rf_ab2026", 74) + I._check_printing("uk_rf_ab2026", 28, bound, point) + point.conditions["sign_convention"] = "positive = loss to households" + point.value = -point.value + point.conditions["value_verbatim"] = "-£145" + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_rf_ab2026", 28, bound, point) + + +def test_two_bounds_merge_only_in_the_same_direction(): + """HM Treasury counts up to 20 million households in two printings, and we + merge one into the other. If it printed at least 20 million in one of them, + the two would bound the count from opposite sides, so the ingest raises.""" + repeat, kept = _claim("uk_hmt_redbook", 180), _claim("uk_hmt_redbook", 7) + assert {s.conditions["estimate_kind"] for s in (repeat, kept)} == {"range_high"} + I._check_printing("uk_hmt_redbook", 180, repeat, kept) + kept.conditions["estimate_kind"] = "range_low" + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_hmt_redbook", 180, repeat, kept) + + +def test_a_share_half_a_point_from_its_rounding_agrees(): + """58% and 57.5% differ by exactly half of 58%'s + last digit. In binary floating point, 0.58 - 0.575 = + 0.0050000000000000044, so the ingest allows a few units in the last place + of each value.""" + repeat, kept = _claim("uk_centax", 62), _claim("uk_centax", 82) + assert repeat.conditions["value_verbatim"] == "58%" + I._check_printing("uk_centax", 62, repeat, _printing(kept, "57.5%", 0.575)) + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_centax", 62, repeat, _printing(kept, "57.4%", 0.574)) + + +def test_a_printing_of_the_opposite_sign_raises(): + """The OBR prints Founders' Relief's 2029-30 effect as a £0.3 billion cut + in receipts in paragraph 3.18 and as -261 in Table 1.1, where it prints a + loss to the Exchequer as negative. If the OBR printed +261 there, a gain, + the two printings would agree in size and differ in direction.""" + repeat, kept = _claim("uk_obr_tables", 2674), _claim("uk_obr_tables", 537) + assert kept.conditions["value_verbatim"] == "-261" + I._check_printing("uk_obr_tables", 2674, repeat, kept) + kept.value = -kept.value + kept.conditions["value_verbatim"] = "261" + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_obr_tables", 2674, repeat, kept) + + +@pytest.mark.parametrize("marks", [(True, False), (False, True), (True, True)]) +def test_a_printing_with_its_direction_in_its_label_agrees_in_size(marks): + """We flip the sign of the workbook's claim for RF's fuel freeze path, so + the ingest raises. Then we mark one printing or both as giving its direction + in its label, as ``signs.classify`` reads it. The ingest can't orient that + printing, so it compares the two magnitudes and accepts the pair.""" + repeat, kept = _claim(*FREEZE_LABEL), _claim(*FREEZE_CELL) + kept.value = -kept.value + with pytest.raises(ValueError, match="no longer matches"): + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + for s, mark in zip((repeat, kept), marks): + if mark: + s.conditions["sign_convention"] = signs.MAGNITUDE_CONVENTION + I._check_printing("uk_rf_ab2026", 147, repeat, kept) + + +_AFFIXES = st.sampled_from([("", ""), ("£", ""), ("£", " billion"), ("", "%")]) + + +@settings(max_examples=500, deadline=None) +@given( + whole=st.integers(1, 999_999), + places=st.integers(0, 6), + data=st.data(), + power=st.integers(-6, 12), + commas=st.booleans(), + affixes=_AFFIXES, +) +def test_the_last_printed_digit_sets_the_place( + whole, places, data, power, commas, affixes +): + fraction = data.draw(st.integers(0, 10**places - 1)) + digits = f"{whole:,}" if commas else str(whole) + printed = digits + (f".{fraction:0{places}d}" if places else "") + number = whole + fraction / 10**places + s = SimpleNamespace( + conditions={"value_verbatim": affixes[0] + printed + affixes[1]}, + value=-number * 10.0**power, + ) + assert math.isclose(I._printed_place(s), 10.0 ** (power - places), rel_tol=1e-9), ( + printed + ) + + +@settings(max_examples=200, deadline=None) +@given( + mantissa=st.integers(1, 9_999_999), + exponent=st.integers(-4, 4), + power=st.integers(-3, 9), +) +def test_a_workbook_exponent_moves_the_place(mantissa, exponent, power): + """RF writes '1.835872215777723E-2' in its workbook, with the last digit + at 10**-17.""" + text = f"{mantissa / 10**6:.6f}E{exponent}" + s = SimpleNamespace( + conditions={"value_verbatim": text}, + value=mantissa / 10**6 * 10.0**exponent * 10.0**power, + ) + assert math.isclose( + I._printed_place(s), 10.0 ** (power + exponent - 6), rel_tol=1e-9 + ), text + + +@settings(max_examples=200, deadline=None) +@given( + number=st.integers(1, 999_999), + factor=st.integers(2, 9), + power=st.integers(-6, 12), +) +def test_a_value_other_than_its_printing_times_a_power_of_ten_raises( + number, factor, power +): + s = SimpleNamespace( + conditions={"value_verbatim": f"£{number}"}, + value=number * factor * 10.0**power, + ) + with pytest.raises(ValueError, match="doesn't match printed"): + I._printed_place(s) + + +@pytest.mark.parametrize( + "printed, value", + [("over a million", 1_000_000.0), ("£0", 0.0), ("0.0", 0.0), ("£5", 0.0)], +) +def test_a_printing_without_digits_or_of_zero_has_no_place(printed, value): + assert ( + I._printed_place( + SimpleNamespace(conditions={"value_verbatim": printed}, value=value) + ) + == 0.0 + ) + + # --- the metric calls ---------------------------------------------------------- @@ -404,8 +1463,10 @@ def test_the_freeze_claims_score_against_the_obrs_latest_policy_world(staged): assert {s.conditions["baseline_policy"] for s in latest} == { "obr_october_2026_budget_forecast" } + # we merge 57 of the pre-measures world's 2,702 claims into other + # printings of their figures (REPEATED_PRINTINGS), so 2,645 remain assert Counter((s.reform.baseline or {}).get("policy") for s in obr) == { - "obr_pre_measures_autumn_budget_2026": 2702, + "obr_pre_measures_autumn_budget_2026": 2645, "obr_october_2026_budget_forecast": 2, "obr_fuel_duty_rpi_uprated_since_2010_11": 1, None: 7, @@ -597,8 +1658,10 @@ def test_any_sample_of_the_harvest_closes_its_accounting(seed, share): assert v["ingested"] + v["dropped"] == v["read"] assert v["read"] == sum(1 for f, _ in sample if f == fam) base_ids = {s.claim_id() for s in BASE[0]} - assert {s.claim_id() for s in scores} <= base_ids | { - # a sample can keep a twin whose Table 6.1 row it left out + # the ingest keeps a repeat whose kept printing we left out of the sample + repeats = {_staged_alone(*row).claim_id() for row in I.REPEATED_PRINTINGS} + assert {s.claim_id() for s in scores} <= base_ids | repeats | { + # and a twin whose Table 6.1 row we left out s.claim_id() for s in scores if s.publication["family"] in I._TWIN_FAMILIES