Repository navigation
Conversation
A simulated instrument keeps each family and sets state_fips to one state after another, so whatever else the file says about the old state has to yield. Stored state labels now follow state_fips, and local geography that contradicts it becomes unknown for that household with a logged warning. Warnings go through logging because this package silences the warnings module. The SPM composition error now names the columns that clear it, and is_spm_independent_minor_role declares itself a source input so exports keep it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A county stored for another year escaped the check, because it compared only periods that stored geography, and only text values. Compare what each year reads, carried values included, and read numbers as evidence of a state without rewriting them: spm.py refuses numeric counties on purpose, and a bare 5 can be a CPS within-state code. county took the latest known period, which includes values the simulation calculated, so 2025 inherited 2024's county when 2024 ran first. Only inputs count now. Stored copies of what the model derives from the state or from stale local geography go, so their formulas run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restore matching observations across state changes, retain county provenance and preserve unaffected rows. Clarify input diagnostics and route flat-file integration tests to the microsimulation suite. Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10574 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 24 117 +93
=========================================
+ Hits 24 117 +93
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets a researcher run one flat file through each state by setting
state_fips. Depends on PolicyEngine/policyengine-core#646, which has to ship first. Stays a draft until that release lands and the core pin moves here.What was wrong
A file can place a household through several columns, and this loop changes one of them. What the file still said about the old state then contradicted it:
county_fipskept the old county's SPM thresholds under the new state's rules, and crashed county-keyed parameters such as Minnesota's CCAP rates withParameterNotFoundError.state_codekept the old state's rules altogether, with no error.county_fips, which is whatread_csvgives for 06037, quietly became the first county in the state. A five-digit one such as 36061 resolved to its county in any state.county_fips__2023withstate_fips__2024kept Los Angeles in Mississippi, and so did a state that changed between two years of one file.countyread "the latest known period", which includes values the simulation had calculated. So 2025 took 2024's county when 2024 ran first, and the answer depended on calculation order.state_groupkept Alaska on the contiguous poverty guideline.What changes
state_fipsdecides the state (policyengine_us/tools/geography/state_assignment.py). Both simulation classes reconcile dataset geography after building the baseline. Each arm uses its own formulas to recompute stale geography.state_code,state_nameorstate_code_strthat disagrees takes the valuestate_fipsimplies.state_group,state_group_str,tax_unit_state,spm_unit_state_fips, the in-state flags) goes if it disagrees, so its formula runs. Agreeing labels and copies stay recorded as inputs.in_ala). SPM county thresholds still require a valid textcounty_fips.in_nyc,in_ny_mctd_zone_2,medicaid_rating_area,three_digit_zip_code) under its own policy. The other rows keep their stored values.county_fipsremains, points to{"geography_kind": "national"}for SPM thresholds. It goes throughloggingbecause this package silences thewarningsmodule.countyreads recorded inputs.latest_readable_countyprefers the latest input in force, so a calculated county stays in its own year. When reconciliation replaces a later input, an earlier year keeps the county it read.state_fipswith no state in the model, such as a territory other than Puerto Rico, raises aValueErrorat load that says what the model covers. Acounty_fipsthat holds numbers logs what that costs, a text code that names no county logs its fallback, and astate_fipsthat differs between a file's years logs a warning.__ETERNITYsuffix that a filter on one year's columns drops. The error code stays the same.source_input_variablesdeclares the SPM source role (is_spm_independent_minor_role) and the observedcountyandcounty_str, so the export with core from Make flat-file datasets safe to load, map and round-trip policyengine-core#646 keeps them (needs the core release). The period export follows core's selection rules.Decisions
Each failure in the slide's path, and what this PR does with it:
countyandcounty_strare declared here__ETERNITYcolumns get lost, then SPM failsperiod=export keeps them. Roles stay unsynthesized, asspm.pyrequiresstate_fipscovers one year of a multi-year exportpolicyengine.pyhelper sets every yearmap_toon text variables failsTreating contradicting geography as unknown, rather than refusing the file, is a judgment call. A refusal would make the slide's loop fail on any file that holds a county. The warning covers the case where the contradiction means a damaged file.
This PR does not repair numeric counties.
test_spm_system.pypins that SPM refuses them, and a bare 5 can be a legacy CPS within-state code, so zero-filling it would invent a county. Numbers count only as evidence of a contradiction: 36061 or 6037 in Minnesota names another state. Thepolicyengine.pyhelper does repair them, because its caller has told it the column holds county FIPS codes.A household already in the target state keeps its real county. So on a sample through the loop, New York's five NYC households differ from the same file with county dropped by hand, and they should.
Invariants
state_fipsimplies, in every year with a state.test_state_fips_always_decides_the_state, and over two-year files with a county in any of three years intest_every_year_reads_a_county_in_its_own_state.countyfor a year does not depend on which years ran first.Tests
test_state_assignment.py: nine household regressions pass against both the locked core (3.37.2) and core from Make flat-file datasets safe to load, map and round-trip policyengine-core#646.test_local_sales_tax_county_carryover.py: four carryover tests pass against the locked core.state_assignment.yamland the 13 other test files that mentionin_alaorcounty_is_imputed.test_flat_file_state_swap.py,test_county_branch_reuse.py,test_county_from_dataset.py,test_local_sales_tax_county_carryover.pyandtest_spm_system.pygave 186 passes. That run predates commit1f05698533and has not been rerun.Real-data checks
These checks predate commit
1f05698533, which keeps agreeing county observations and stops the county fallback from establishing Alameda residence, and have not been rerun. They ran against core at this branch's companion head, on Populace USpopulace-us-2024-spm-20260909:state_codewas right in all 51. SNAP eligibility took 26 distinct values, Medicaid eligibility 46, state income tax 45, and national SPM thresholds exactly one. Each state took about 6.6 seconds.household_net_income,state_income_tax,is_snap_eligible,is_medicaid_eligibleandmn_child_care_subsidies: no differences except the five NYC households above.Follow-ups
policyengine.pypins an older model and cannot reach these fixes yet, so Run a researcher's flat file through each state's rules policyengine.py#733 carries a helper that works at its pins.axiom: n/a: dataset input handling, no policy change
🤖 Generated with Claude Code