From 0fbf586b4f32a493a174d12bca9d1bf35c515d60 Mon Sep 17 00:00:00 2001 From: PavelMakarchuk Date: Wed, 18 Mar 2026 13:48:12 -0400 Subject: [PATCH 1/3] Fix climate_action_incentive_category enum crash select() with no default returns 0 (int) when no condition matches, which fails enum encoding. This happens for children in two-parent households who don't match any of the four conditions. Add default=OTHER_CHILD so unmatched persons get a valid enum value. This unblocks household_net_income and marginal_tax_rate calculations. Co-Authored-By: Claude Opus 4.6 --- .../credits/climate_action/climate_action_incentive_category.py | 1 + 1 file changed, 1 insertion(+) diff --git a/policyengine_canada/variables/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.py b/policyengine_canada/variables/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.py index fae5243d2..dc590c854 100644 --- a/policyengine_canada/variables/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.py +++ b/policyengine_canada/variables/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.py @@ -41,4 +41,5 @@ def formula(person, period, parameters): ClimateActionIncentiveCategory.ELDEST_CHILD_IN_SINGLE_PARENT_HOUSEHOLD, ClimateActionIncentiveCategory.OTHER_CHILD, ], + default=ClimateActionIncentiveCategory.OTHER_CHILD, ) From a70089a67081af219a66b1d8f51bc2e3ff1944e3 Mon Sep 17 00:00:00 2001 From: PavelMakarchuk Date: Wed, 18 Mar 2026 13:50:22 -0400 Subject: [PATCH 2/3] Add tests for climate_action_incentive_category fix - Test category assignment for two-parent household with child (the crash case) - Test single-parent household eldest child gets special category - Test single person gets HEAD - Integration test for two-parent and married-couple households Co-Authored-By: Claude Opus 4.6 --- .../climate_action_incentive_category.yaml | 74 +++++++++++++++++++ .../integration_two_parent.yaml | 53 +++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.yaml create mode 100644 policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/integration_two_parent.yaml diff --git a/policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.yaml b/policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.yaml new file mode 100644 index 000000000..9e9a88029 --- /dev/null +++ b/policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.yaml @@ -0,0 +1,74 @@ +- name: Two-parent household with child — category defaults without crash + period: 2026 + input: + people: + parent1: + age: 35 + is_head: true + is_spouse: false + employment_income: 50_000 + parent2: + age: 33 + is_head: false + is_spouse: true + child: + age: 5 + is_head: false + is_spouse: false + households: + household: + members: [parent1, parent2, child] + province_code: ONT + is_married: true + output: + climate_action_incentive_category: + - HEAD + - SPOUSE + - OTHER_CHILD + +- name: Single parent household — eldest child gets special category + period: 2026 + input: + people: + parent: + age: 35 + is_head: true + is_spouse: false + employment_income: 45_000 + child1: + age: 10 + is_head: false + is_spouse: false + is_dependant: true + child2: + age: 7 + is_head: false + is_spouse: false + is_dependant: true + households: + household: + members: [parent, child1, child2] + province_code: ONT + is_married: false + output: + climate_action_incentive_category: + - HEAD + - ELDEST_CHILD_IN_SINGLE_PARENT_HOUSEHOLD + - OTHER_CHILD + +- name: Single person — head only + period: 2026 + input: + people: + person: + age: 40 + is_head: true + is_spouse: false + employment_income: 90_000 + households: + household: + members: [person] + province_code: ONT + output: + climate_action_incentive_category: + - HEAD diff --git a/policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/integration_two_parent.yaml b/policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/integration_two_parent.yaml new file mode 100644 index 000000000..bc5efc3f6 --- /dev/null +++ b/policyengine_canada/tests/gov/cra/tax/income/credits/climate_action/integration_two_parent.yaml @@ -0,0 +1,53 @@ +- name: Two-parent household with child — household_net_income does not crash + period: 2026 + absolute_error_margin: 1 + input: + people: + parent1: + age: 35 + is_head: true + is_spouse: false + employment_income: 50_000 + parent2: + age: 33 + is_head: false + is_spouse: true + employment_income: 30_000 + child: + age: 5 + is_head: false + is_spouse: false + households: + household: + members: [parent1, parent2, child] + province_code: ONT + is_married: true + output: + climate_action_incentive_category: + - HEAD + - SPOUSE + - OTHER_CHILD + +- name: Married couple no children — climate action does not crash + period: 2026 + absolute_error_margin: 1 + input: + people: + head: + age: 40 + is_head: true + is_spouse: false + employment_income: 90_000 + spouse: + age: 38 + is_head: false + is_spouse: true + households: + household: + members: [head, spouse] + province_code: ONT + is_married: true + output: + climate_action_incentive_category: + - HEAD + - SPOUSE From 994de8dcf43626337c6689749cf30d2779f44e66 Mon Sep 17 00:00:00 2001 From: PavelMakarchuk Date: Wed, 18 Mar 2026 13:54:40 -0400 Subject: [PATCH 3/3] Add changelog entry for climate action category fix Co-Authored-By: Claude Opus 4.6 --- changelog.d/fixed/fix-climate-action-category.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/fixed/fix-climate-action-category.md diff --git a/changelog.d/fixed/fix-climate-action-category.md b/changelog.d/fixed/fix-climate-action-category.md new file mode 100644 index 000000000..2790eebf0 --- /dev/null +++ b/changelog.d/fixed/fix-climate-action-category.md @@ -0,0 +1 @@ +Fixed climate_action_incentive_category enum crash that broke household_net_income and marginal_tax_rate for all household types.