diff --git a/changelog.d/md-local-unknown-county.fixed.md b/changelog.d/md-local-unknown-county.fixed.md new file mode 100644 index 00000000000..0c4116ed241 --- /dev/null +++ b/changelog.d/md-local-unknown-county.fixed.md @@ -0,0 +1 @@ +Fixed crashes in the Maryland local tax variables md_applicable_local_tax_rate and md_flat_rate_county_tax for Maryland households whose county is unknown, by falling back to the same default county used elsewhere. diff --git a/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_applicable_local_tax_rate.yaml b/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_applicable_local_tax_rate.yaml index d54580bf9d6..9a1cee15d62 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_applicable_local_tax_rate.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_applicable_local_tax_rate.yaml @@ -48,3 +48,23 @@ county_str: FREDERICK_COUNTY_MD output: md_applicable_local_tax_rate: 0.0296 + +- name: Allegany County uses its flat rate (2025) + period: 2025 + absolute_error_margin: 0.0001 + input: + state_code_str: MD + county_str: ALLEGANY_COUNTY_MD + output: + md_applicable_local_tax_rate: 0.0303 + +- name: Unknown county in an MD household falls back to Allegany County (issue #8975) + period: 2025 + absolute_error_margin: 0.0001 + input: + state_code_str: MD + county_str: UNKNOWN + output: + # gov.local.md.flat_rate has no UNKNOWN key; the formula falls back to + # ALLEGANY_COUNTY_MD. Before the fix this raised ParameterNotFoundError. + md_applicable_local_tax_rate: 0.0303 diff --git a/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_flat_rate_county_tax.yaml b/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_flat_rate_county_tax.yaml new file mode 100644 index 00000000000..795e980bb3c --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/states/md/tax/income/local/md_flat_rate_county_tax.yaml @@ -0,0 +1,23 @@ +- name: Allegany County MD flat rate county tax baseline (2025) + period: 2025 + absolute_error_margin: 0.01 + input: + state_code_str: MD + county_str: ALLEGANY_COUNTY_MD + md_taxable_income: 30_000 + output: + # 3.03% Allegany rate * 30,000 = 909 + md_flat_rate_county_tax: 909 + +- name: Unknown county in an MD household falls back to Allegany County (issue #8975) + period: 2025 + absolute_error_margin: 0.01 + input: + state_code_str: MD + county_str: UNKNOWN + md_taxable_income: 30_000 + output: + # gov.local.md.flat_rate has no UNKNOWN key; the formula falls back to + # ALLEGANY_COUNTY_MD, so this must equal the Allegany baseline above. + # Before the fix this raised ParameterNotFoundError instead of computing. + md_flat_rate_county_tax: 909 diff --git a/policyengine_us/variables/gov/states/md/tax/income/local/md_applicable_local_tax_rate.py b/policyengine_us/variables/gov/states/md/tax/income/local/md_applicable_local_tax_rate.py index ad626d0096a..7db28e18d56 100644 --- a/policyengine_us/variables/gov/states/md/tax/income/local/md_applicable_local_tax_rate.py +++ b/policyengine_us/variables/gov/states/md/tax/income/local/md_applicable_local_tax_rate.py @@ -19,7 +19,11 @@ def formula(tax_unit, period, parameters): # Guard against non-MD counties in microsimulation: # defined_for masks results but doesn't prevent formula execution. in_md = tax_unit.household("state_code_str", period) == "MD" - safe_county = where(in_md, county, "ALLEGANY_COUNTY_MD") + # Fall back to a default MD county when the county is unknown/unmapped + # (County.UNKNOWN is the default), since gov.local.md.flat_rate has no + # UNKNOWN key and would otherwise raise ParameterNotFoundError. The + # non-MD path already falls back to the same default county. + safe_county = where(in_md & (county != "UNKNOWN"), county, "ALLEGANY_COUNTY_MD") p = parameters(period).gov.local.md flat_rate = p.flat_rate[safe_county] diff --git a/policyengine_us/variables/gov/states/md/tax/income/local/md_flat_rate_county_tax.py b/policyengine_us/variables/gov/states/md/tax/income/local/md_flat_rate_county_tax.py index 784c45006fe..447cad93edf 100644 --- a/policyengine_us/variables/gov/states/md/tax/income/local/md_flat_rate_county_tax.py +++ b/policyengine_us/variables/gov/states/md/tax/income/local/md_flat_rate_county_tax.py @@ -17,7 +17,11 @@ def formula(tax_unit, period, parameters): # Guard against non-MD counties in microsimulation # defined_for masks results but doesn't prevent formula execution in_md = tax_unit.household("state_code_str", period) == "MD" - safe_county = where(in_md, county, "ALLEGANY_COUNTY_MD") + # Fall back to a default MD county when the county is unknown/unmapped + # (County.UNKNOWN is the default), since gov.local.md.flat_rate has no + # UNKNOWN key and would otherwise raise ParameterNotFoundError. The + # non-MD path already falls back to the same default county. + safe_county = where(in_md & (county != "UNKNOWN"), county, "ALLEGANY_COUNTY_MD") p = parameters(period).gov.local.md.flat_rate flat_rate = p[safe_county]