From cb16bc360f8a34ad269f4b4e68018cd1ddd4c813 Mon Sep 17 00:00:00 2001 From: WesIngwersen Date: Fri, 13 Nov 2026 11:17:14 -0500 Subject: [PATCH] feat(nowcast): hold the services seed's AIES years on the SAS 2022 index, and move trucking's electricity on warehousing's (#1304) Flag hold_services_seed_at_last_sas_year, off. From AIES 2023 to 2024, purchased electricity moves beyond any SAS-era year in 20 of 48 survey industries, and other items grow 40-80% in one year in many, so every AIES year now takes the SAS 2022 relative index. Under the same flag, trucking's electricity cell takes warehousing's electricity index: its electricity is terminals and depots, not its fleet. Co-Authored-By: Claude Opus 5.5 --- .../services_transport_expense_seed.py | 43 ++++++++++++++++--- .../__tests__/test_nowcast_intermediate.py | 36 ++++++++++++++++ bedrock/utils/config/usa_config.py | 6 +++ 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/bedrock/analysis/nowcasting/services_transport_expense_seed.py b/bedrock/analysis/nowcasting/services_transport_expense_seed.py index ace8614f5..27a68226f 100644 --- a/bedrock/analysis/nowcasting/services_transport_expense_seed.py +++ b/bedrock/analysis/nowcasting/services_transport_expense_seed.py @@ -1168,18 +1168,43 @@ def _chain_across_aies() -> bool: return get_usa_config().chain_services_seed_across_aies +#: The electricity commodity of the Use rows the seed moves. +ELECTRICITY_COMMODITY = '221100' + +#: Industries whose electricity cell moves on another industry's survey index +#: under ``hold_services_seed_at_last_sas_year`` (#1304). Trucking's electricity +#: is its terminals and depots, buildings like warehousing's: its fleet isn't +#: electrified (Wes, 2026-11-13). Its own survey item steps x1.5 from AIES 2023 +#: to 2024, beyond any SAS-era year. CBECS gives warehouses 13,107 kWh per worker +#: in 2018, against BEA's 2017 implied 15,283 for warehousing and 17,394 for +#: trucking. +ELECTRICITY_PROXY_INDUSTRIES = {'484000': '493000'} + + +def _hold_at_last_sas_year() -> bool: + from bedrock.utils.config.usa_config import get_usa_config # noqa: PLC0415 + + return get_usa_config().hold_services_seed_at_last_sas_year + + def _chained_index(naics: str, year: int, base_year: int) -> pd.Series: """:data:`LAST_SAS_YEAR`'s SAS index, moved on AIES's own ratios to *year*. ``index(2022 vs base)`` on the SAS panel, times ``index(year vs 2023)`` on the AIES panel. A commodity only one side reaches keeps that side's index (the other contributes 1.0, no movement). + + ⚠️ With ``hold_services_seed_at_last_sas_year``, every AIES year takes the SAS + index alone (#1304). From 2023 to 2024 the AIES moves purchased electricity + beyond any SAS-era year in 20 of 48 survey industries, and many industries' + other items grow 40-80% in that one year, so the relative index divides by a + bill that changes for reasons other than growth. """ sas = relative_index( naics, LAST_SAS_YEAR, base_year=base_year, panel=_panel_for(LAST_SAS_YEAR) ) first = AIES_OBSERVED_YEARS[0] - if year == first: + if year == first or _hold_at_last_sas_year(): return sas aies = relative_index(naics, year, base_year=first, panel=_panel_for(year)) codes = sas.index.union(aies.index) @@ -1245,12 +1270,20 @@ def services_transport_seed( chained = year in AIES_OBSERVED_YEARS and _chain_across_aies() panel = _panel_for(LAST_SAS_YEAR if chained else year) + def survey_index(naics: str) -> pd.Series: + if chained: + return _chained_index(naics, year, base_year) + return relative_index(naics, year, base_year=base_year, panel=panel) + for industry in columns: naics = _bea_to_survey_industry()[industry] - if chained: - index = _chained_index(naics, year, base_year) - else: - index = relative_index(naics, year, base_year=base_year, panel=panel) + index = survey_index(naics) + proxy = ELECTRICITY_PROXY_INDUSTRIES.get(industry) + if proxy is not None and _hold_at_last_sas_year(): + borrowed = survey_index(_bea_to_survey_industry()[proxy]) + if ELECTRICITY_COMMODITY in borrowed.index: + index = index.copy() + index[ELECTRICITY_COMMODITY] = borrowed[ELECTRICITY_COMMODITY] if index.empty: continue touched = [code for code in index.index if code in seed.index] diff --git a/bedrock/transform/iot/__tests__/test_nowcast_intermediate.py b/bedrock/transform/iot/__tests__/test_nowcast_intermediate.py index 9d74da12d..f3428276d 100644 --- a/bedrock/transform/iot/__tests__/test_nowcast_intermediate.py +++ b/bedrock/transform/iot/__tests__/test_nowcast_intermediate.py @@ -854,6 +854,42 @@ def test_services_seed_chains_across_the_survey_change( assert float((indexed_2023 - chained_2022).abs().to_numpy().max()) > 0.0 +@needs_census +def test_the_held_seed_takes_no_aies_movement_and_trucking_follows_warehousing( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """With the hold, 2024 is 2023, and trucking's electricity follows warehousing's. + + #1304: AIES 2024 against AIES 2023 isn't used. Trucking's electricity cell + takes warehousing's electricity index, so in 2022 the two cells move by about + the same factor against their own 2017 shares. + """ + from bedrock.analysis.nowcasting import ( # noqa: PLC0415 + services_transport_expense_seed as st, + ) + + monkeypatch.setattr(st, '_hold_at_last_sas_year', lambda: True) + pd.testing.assert_frame_equal( + st.services_transport_seed(2024), st.services_transport_seed(2023) + ) + + use = st._use_2017_detail() + held = st.services_transport_seed(2022) + elec = st.ELECTRICITY_COMMODITY + + def share_change(seed: pd.DataFrame, industry: str) -> float: + column = pd.Series(seed[industry], dtype=float) + base = pd.Series(use[industry], dtype=float) + return (column[elec] / column.sum()) / (base[elec] / base.sum()) + + monkeypatch.setattr(st, '_hold_at_last_sas_year', lambda: False) + own = st.services_transport_seed(2022) + assert share_change(own, '484000') != pytest.approx(share_change(held, '484000')) + assert share_change(held, '484000') == pytest.approx( + share_change(held, '493000'), rel=0.05 + ) + + # --- electric power's refined petroleum on price (#922) ------------------------ diff --git a/bedrock/utils/config/usa_config.py b/bedrock/utils/config/usa_config.py index e985be69e..f51937b97 100644 --- a/bedrock/utils/config/usa_config.py +++ b/bedrock/utils/config/usa_config.py @@ -271,6 +271,12 @@ class USAConfig(BaseModel): # cut every buyer ~16% to close it (trade -24%). See # bedrock.analysis.nowcasting.services_transport_expense_seed. chain_services_seed_across_aies: bool = True # DRI: WesIngwersen + # With the chain on, hold every AIES year on 2022's SAS relative index + # instead of moving 2024 on AIES 2024/2023. That step isn't safe inside + # the AIES either: purchased electricity moves beyond any SAS-era year in + # 20 of 48 survey industries (warehousing x3.7, legal x0.53), and other + # items grow 40-80% in one year in many (#1304). + hold_services_seed_at_last_sas_year: bool = False # DRI: WesIngwersen # Chain the truck and water transport margins across the SAS -> AIES # change: 2023 keeps 2022's margin as a share of the mode's gross output, # and 2024 moves on AIES's own 2024/2023 revenue. AIES's Table 8 covers