Skip to content

Upgrade breakdown enum mismatch from WARNING to ERROR#445

Open
MaxGhenis wants to merge 1 commit intoPolicyEngine:masterfrom
MaxGhenis:fix-breakdown-mismatch-error
Open

Upgrade breakdown enum mismatch from WARNING to ERROR#445
MaxGhenis wants to merge 1 commit intoPolicyEngine:masterfrom
MaxGhenis:fix-breakdown-mismatch-error

Conversation

@MaxGhenis
Copy link
Contributor

Summary

Parameters with keys not in the breakdown variable's possible values now raise ValueError instead of silently logging a warning. This prevents data loss when parameter YAML files use keys that don't match the breakdown enum.

For example, SNAP utility allowance parameters with breakdown: [state_code] but using snap_utility_region keys (AK_C, NY_NYC, etc.) were silently dropped — only a WARNING was logged. This caused real data loss in PolicyEngine/policyengine-us#7726.

Changes

  • homogenize_parameters.py: Collect all extra children (keys not in breakdown enum) and raise ValueError with a clear message listing the offending keys
  • test_nesting.py: Add tests for both the error case (extra keys → ValueError) and the allowed case (partial coverage → no error)

Design

  • yaml_keys - enum_values non-empty → ERROR (unknown keys that would be silently dropped)
  • enum_values - yaml_keys non-empty → OK (partial coverage is intentional, e.g. state_code breakdown omitting armed forces codes)

Closes #444

Test plan

  • Existing test_parameter_homogenization still passes (valid breakdown)
  • New test_breakdown_mismatch_raises_error passes (extra key raises ValueError)
  • New test_breakdown_partial_coverage_is_ok passes (missing enum values allowed)
  • CI passes on all Python versions

🤖 Generated with Claude Code

Parameters with keys not in the breakdown variable's possible values
now raise ValueError instead of silently logging a warning. This
prevents data loss when parameter YAML files use keys that don't match
the breakdown enum (e.g., using snap_utility_region keys with a
state_code breakdown).

Partial coverage (enum values missing from YAML) remains allowed.

Closes PolicyEngine#444

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade breakdown enum mismatch from WARNING to ERROR

1 participant