From 543b850cee060aed80e7fc3a1d87072f885eb3bd Mon Sep 17 00:00:00 2001 From: Marvin Immesberger Date: Tue, 9 Jun 2026 14:12:36 +0200 Subject: [PATCH 1/2] Add ruff exceptions discovered in GETTSIM. --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 211ad9ded..8a0bf353e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,6 +209,8 @@ per-file-ignores."src/ttsim/typing.py" = [ "PYI051", # Redundant literal union ] per-file-ignores."src_mettsim/mettsim/middle_earth/**/*.py" = [ + "PLR1714", # Consider merging multiple comparisons with `in` — not vectorizable + "PLR1716", # Boolean expression may be simplified with chained comparison — not vectorizable "PLR2004", # Magic value comparison "RET505", # Vectorizer requires both if/else branches; it rejects the early-return form ] From 3c2db2b64e8587312ccb267eee7f5eca5a4837fa Mon Sep 17 00:00:00 2001 From: Marvin Immesberger Date: Tue, 9 Jun 2026 14:31:29 +0200 Subject: [PATCH 2/2] Add ruff violations that we ignore now. --- src_mettsim/mettsim/middle_earth/demographics.py | 12 +++++++++++- .../housing_benefits/eligibility/eligibility.py | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src_mettsim/mettsim/middle_earth/demographics.py b/src_mettsim/mettsim/middle_earth/demographics.py index 1705c02a1..0dd68cd2d 100644 --- a/src_mettsim/mettsim/middle_earth/demographics.py +++ b/src_mettsim/mettsim/middle_earth/demographics.py @@ -1,6 +1,6 @@ from __future__ import annotations -from ttsim.tt import AggType, agg_by_group_function +from ttsim.tt import AggType, agg_by_group_function, policy_function @agg_by_group_function(agg_type=AggType.COUNT) @@ -8,3 +8,13 @@ def number_of_individuals_kin( kin_id: int, # noqa: ARG001 ) -> int: return 1 + + +@policy_function(vectorization_strategy="vectorize") +def coming_of_age_celebration(age: int) -> bool: + """Whether the person reaches a coming-of-age milestone this year. + + Hobbits come of age at 33 and famously celebrate their eleventy-first + (111th) birthday. + """ + return age == 33 or age == 111 diff --git a/src_mettsim/mettsim/middle_earth/housing_benefits/eligibility/eligibility.py b/src_mettsim/mettsim/middle_earth/housing_benefits/eligibility/eligibility.py index 8abbd9dc7..3d822ac0e 100644 --- a/src_mettsim/mettsim/middle_earth/housing_benefits/eligibility/eligibility.py +++ b/src_mettsim/mettsim/middle_earth/housing_benefits/eligibility/eligibility.py @@ -80,3 +80,12 @@ def adult( max_age_children: int, ) -> bool: return age > max_age_children + + +@policy_function(vectorization_strategy="vectorize") +def young_adult( + age: int, + max_age_children: int, +) -> bool: + """Whether the person is a young adult: past child age but not yet of age.""" + return max_age_children < age and age < 33