Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/us-2036-economy-year.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Offer 2036 as a US society-wide year (US 2024 to 2036), for the PolicyEngine bundle whose SPM forecast covers 2022–2036.
4 changes: 2 additions & 2 deletions docs/canonical-spm.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The `spm` object accepts only these fields:
Unknown fields and invalid selections are rejected. Only the household's
`county_fips` input identifies a local county. Computed county, state, first county
in state and congressional district do not identify an SPM area. The full
canonical artifact supplies 2022–2035 measurements; no consumer CPI extrapolation
canonical artifact supplies 2022–2036 measurements; no consumer CPI extrapolation
or congressional-district geographic factors are introduced.

`POST /us/calculate` and `/us/calculate-full` take settings beside the existing
Expand Down Expand Up @@ -329,7 +329,7 @@ annual requests require `time_period`, while budget-window requests require
`start_year` and `window_size` (1–75, ending no later than 2099). Years use four
digits. An annual `time_period`, and a budget window's `start_year`, must be
one of the country's years in `/{country}/metadata`'s
`economy_options.time_period` (US 2024 to 2035, UK 2024 to 2032, from
`economy_options.time_period` (US 2024 to 2036, UK 2024 to 2032, from
`policyengine_api/economy_years.py`). Any other year returns HTTP 400 with the
code `DATASET_YEAR_UNAVAILABLE` in `errors`, before anything is read from the
cache or submitted, even when a result for that year is stored. A budget
Expand Down
2 changes: 1 addition & 1 deletion docs/migration/stage-9-v2-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ A catalog version's time-period options (`metadata_time_periods`), the years
`/v2/economy-options` offers for it, come from the Public API's code, not from
PolicyEngine.py: each country's years are defined once in
`policyengine_api/economy_years.py`, which `/{country}/metadata` offers in
`economy_options.time_period` and the economy routes accept (US 2024 to 2035,
`economy_options.time_period` and the economy routes accept (US 2024 to 2036,
newest first; UK 2024 to 2032, oldest first). They can therefore change while
the PolicyEngine.py version stays the same, so republication does not compare
them. After every other table and column of a stored version has been
Expand Down
6 changes: 4 additions & 2 deletions policyengine_api/economy_years.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
Each list keeps the order both responses have always used: the US newest
first, the UK oldest first.

- The US years start in 2024: 2022 and 2023 are no longer offered.
- The US years start in 2024: 2022 and 2023 are no longer offered. They end
with 2036, the last year of the canonical SPM forecast in the bundle
(spm-calculator 1.1.0 covers 2022 to 2036).
- The UK years start with 2024, the data year of the UK dataset
(microcosm_uk_2024_25), and end with 2032, the last year policyengine-uk
2.151.0 projects that dataset to (``PROJECTION_END_YEAR``). The simulation
Expand All @@ -24,7 +26,7 @@
if TYPE_CHECKING:
from collections.abc import Mapping

US_ECONOMY_YEARS: Final[tuple[int, ...]] = tuple(range(2035, 2023, -1))
US_ECONOMY_YEARS: Final[tuple[int, ...]] = tuple(range(2036, 2023, -1))
UK_ECONOMY_YEARS: Final[tuple[int, ...]] = tuple(range(2024, 2033))

ECONOMY_YEARS: Final[Mapping[str, tuple[int, ...]]] = {
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/routes/test_economy_unavailable_years.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def _client() -> Flask:
@pytest.mark.parametrize(
("country_id", "year", "expected_body"),
[
("us", "2022", unavailable_year_body("US", 2024, 2035, "2022")),
("us", "2023", unavailable_year_body("US", 2024, 2035, "2023")),
("us", "2036", unavailable_year_body("US", 2024, 2035, "2036")),
("us", "2022", unavailable_year_body("US", 2024, 2036, "2022")),
("us", "2023", unavailable_year_body("US", 2024, 2036, "2023")),
("us", "2037", unavailable_year_body("US", 2024, 2036, "2037")),
("uk", "2023", unavailable_year_body("UK", 2024, 2032, "2023")),
("uk", "2033", unavailable_year_body("UK", 2024, 2032, "2033")),
],
Expand All @@ -98,8 +98,8 @@ def test_an_annual_year_outside_the_countrys_years_gets_400_and_nothing_runs(
@pytest.mark.parametrize(
("country_id", "start_year", "window_size", "expected_body"),
[
("us", "2023", "3", unavailable_year_body("US", 2024, 2035, "2023")),
("us", "2036", "1", unavailable_year_body("US", 2024, 2035, "2036")),
("us", "2023", "3", unavailable_year_body("US", 2024, 2036, "2023")),
("us", "2037", "1", unavailable_year_body("US", 2024, 2036, "2037")),
("uk", "2023", "2", unavailable_year_body("UK", 2024, 2032, "2023")),
],
)
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_a_stored_result_for_an_unavailable_year_is_not_returned(stored_us_impac
)

assert response.status_code == 400
assert response.json == unavailable_year_body("US", 2024, 2035, "2022")
assert response.json == unavailable_year_body("US", 2024, 2036, "2022")
assert stored_us_impact.gateway.mock_calls == []
assert stored_us_impact.policies.mock_calls == []
stored = stored_us_impact.cache.get_by_execution_id(STORED_EXECUTION_ID)
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/routes/test_spm_year_worker_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
"county_vintage": "2020",
"as_of": None,
}
# The annual requests ask for 2035, the last US year the Public API accepts,
# The annual requests ask for 2036, the last US year the Public API accepts,
# so they reach the worker, which may still refuse the year. The budget windows
# run from 2035 to 2036: they start in a US year, so they reach it too.
ANNUAL_YEAR = "2035"
# run from 2036 to 2037: they start in a US year, so they reach it too.
ANNUAL_YEAR = "2036"
YEAR_ERROR = {
"code": "SPM_YEAR_UNAVAILABLE",
"message": "Forecast has no entry for 2036",
"message": "Forecast has no entry for 2037",
}
DATASET_YEAR_ERROR = {
"code": "DATASET_YEAR_UNAVAILABLE",
"message": (
"US results are available for 2024 to 2035. 2036 is outside the years "
"US results are available for 2024 to 2036. 2037 is outside the years "
"the current US model and data cover."
),
}
Expand Down Expand Up @@ -163,8 +163,8 @@ def _typed_failure(
"kind": "budgetWindow",
"windowSize": 2,
"annualImpacts": [
segmented_result("2035"),
segmented_result("2036", side),
segmented_result("2036"),
segmented_result("2037", side),
],
}
if budget_window
Expand Down Expand Up @@ -236,7 +236,7 @@ def _setup_options(service: EconomyService, *, budget_window: bool) -> Any:
options={},
api_version="1.0.0",
),
time_period="budget_window:2035:2" if budget_window else ANNUAL_YEAR,
time_period="budget_window:2036:2" if budget_window else ANNUAL_YEAR,
)


Expand All @@ -262,7 +262,7 @@ def _economy_request(*, budget_window: bool) -> tuple[str, dict[str, str]]:
"""Return the economy route and query for an annual or budget-window run."""
if budget_window:
return "/us/economy/1/over/2/budget-window", {
"start_year": "2035",
"start_year": "2036",
"window_size": "2",
}
return "/us/economy/1/over/2", {"time_period": ANNUAL_YEAR}
Expand Down Expand Up @@ -491,8 +491,8 @@ def test_an_uncertifiable_stored_result_becomes_terminal_instead_of_repeating(
"kind": "budgetWindow",
"windowSize": 2,
"annualImpacts": [
segmented_result("2035"),
segmented_result("2036", "reform"),
segmented_result("2036"),
segmented_result("2037", "reform"),
],
},
setup.observability_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def test__given_window_ending_after_the_countrys_years__still_submits_it(
"""Only the start year must be one of the country's years.

2034 is a US year, so the window from 2034 to 2038 is submitted as
before, although 2036 to 2038 are after the last US year (2035).
before, although 2037 and 2038 are after the last US year (2036).
"""
base_params["start_year"] = "2034"
base_params["window_size"] = 5
mock_simulation_entrypoint.run_budget_window_batch.return_value = (
create_mock_budget_window_batch_execution(
batch_job_id="fc-budget-after-2035", status="submitted"
batch_job_id="fc-budget-after-2036", status="submitted"
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def get_population(self, entity_plural):

@pytest.mark.parametrize("country_id", ["us", "uk"])
def test__metadata_offers_the_countrys_economy_years_in_their_order(country_id):
"""US 2024 to 2035 newest first, UK 2024 to 2032 oldest first."""
"""US 2024 to 2036 newest first, UK 2024 to 2032 oldest first."""
assert COUNTRIES[country_id].metadata["economy_options"]["time_period"] == [
{"name": year, "label": str(year)} for year in ECONOMY_YEARS[country_id]
]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_country_spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ def household(self, *, axes=False):
),
"year-after-forecast": MissingInputCase(
"SPM_YEAR_UNAVAILABLE",
"Forecast has no entry for 2036",
"Forecast has no entry for 2037",
geography_kind="national",
year="2036",
year="2037",
),
}

Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_economy_years.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from tests.fixtures.v2_catalog import normalized_catalog


def test_us_years_are_2024_to_2035_newest_first():
def test_us_years_are_2024_to_2036_newest_first():
assert US_ECONOMY_YEARS == (
2036,
2035,
2034,
2033,
Expand Down Expand Up @@ -60,7 +61,7 @@ def test_each_extracted_catalog_version_stores_its_countrys_years(country_id):
(
"us",
"2022",
"US results are available for 2024 to 2035. 2022 is outside the "
"US results are available for 2024 to 2036. 2022 is outside the "
"years the current US model and data cover.",
),
(
Expand Down
Loading