Repository navigation
Draw district maps on the boundaries each analysis was computed on - #235
Conversation
The Districts tab fetched ArcGIS's 118th Congress layer, but every analysis runs on the policyengine-us-data state files, which assign households to 119th Congress districts. In the five states that redrew between the two (AL, GA, LA, NC, NY), results were drawn on the wrong boundaries. The map now loads ui-kit's district file for the Congress the results were computed on: model_notes.district_congress, or a year's own districtCongress in multi-year analyses, defaulting to 119 when untagged. The header names the Congress. The 120th Congress can be drawn once ui-kit ships PolicyEngine/policyengine-ui-kit#41; until then a 120 tag falls back to the card view instead of drawing 119th boundaries. Also removes the unused hard-coded 118th Utah map. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wappable compute_impacts.py downloaded the policyengine-us-data state files with no record of which district plan they use. State datasets are now named sources (STATE_DATASETS) chosen with --state-dataset or TRACKER_STATE_DATASET; each says which Congress's districts it assigns households to. The default, us-data-cd119, is the current files (119th Congress block assignments), so nothing changes for existing runs. Each analysis with district results stores model_notes.district_congress, and multi-year analyses also tag each year (districtCongress), so the map can draw matching boundaries. Moving the tracker to the 120th Congress is then one new source entry plus a recompute, once the microcosm release with 120th district assignments exists (microcosm #1526). Also: - warn when a state's district GEOIDs don't match state_fips * 100 + 1..n, which catches a dataset with a different encoding or plan; - Supabase writes take the dataset name from the source, so federal runs record populace-us as the offline path already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Browser check (local dev server, production Supabase data) I opened the Districts tab for three bills in states that redrew between the 118th and 119th Congresses and compared each with production:
I have the screenshots locally if they'd help. |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review: PolicyEngine/state-legislative-tracker PR #235
Verdict: REQUEST_CHANGES (head 9e722f3a1d838b7797e4cc3fd247813cba116c8d)
Summary
The PR replaces the ArcGIS 118th Congress layer with the 119th Congress boundary file from ui-kit 0.9. It tags each analysis with the Congress of its district results (model_notes.district_congress, and districtCongress for each year). The main path is correct. Untagged analyses draw on 119th boundaries, the district IDs match the analysis outputs, and the 119th file has correct ring winding. Build, lint and all tests pass at head and on a test merge with main.
The PR does not depend on policyengine-ui-kit#41 or on its 120th files today. It also does not use state legislative boundaries. A 120 tag is blocked by DRAWABLE_CONGRESSES = [119], and the map falls back to the card view.
That fallback is broken. The card view throws ReferenceError: yearImpacts is not defined in five states, and it shows "District data not available" in all other states. The bug is older than this PR, but the PR makes the card view the designed path for 120-tagged analyses. Alabama and Utah are both card-view states and 120th redraw states.
Findings
CRITICAL
None.
SHOULD ADDRESS
- The documented 120th fallback crashes the page or hides the data.
- Where:
src/components/reform/DistrictMap.jsx:892sends a load error toCardBasedDistrictView. That component readsyearImpactsatsrc/components/reform/DistrictMap.jsx:210and:221, butyearImpactsexists only insideGenericStateDistrictMap. - Failure case: an AL analysis with district results and
model_notes.district_congress = 120.loadStateDistrictsGeorejects (districtGeo.js:79), the card view renders, and React throwsReferenceError: yearImpacts is not defined. The app has no error boundary, so the page goes blank. I reproduced this in a jsdom render ofDistrictMap. The same crash occurs in AZ, OK, SC and UT, which are the other states in the card list. - Failure case 2: the same tag on an NC analysis. The header says "120th Congress districts (from January 3, 2027). Click on a district to see detailed impact analysis". The body says "District data not available for this state", although 14 district results exist.
- Why it is realistic: the PR's own plan adds a 120th dataset source (step 2) and a ui-kit bump (step 1) separately. ui-kit#41 has a REQUEST_CHANGES review, so a recompute on a 120th source can happen first. A failed load of the boundary chunk also reaches this path. That case was also present on main with ArcGIS.
- Fix: give
CardBasedDistrictViewthe year's impacts (orselectedYear), and show a short "boundaries not available for the Nth Congress" note. As an alternative, hide the Districts map and keep the district table until the boundaries ship. Add a render test for the fallback.eslint --rule '{"no-undef":"error"}'finds both lines.
- Where:
SUGGESTION
- Guard against inverted rings before 120 is enabled. The 120th file in ui-kit#41 (head
cf2e5bd) has 437 of 437 features withd3.geoArea >= 2π. If someone bumps ui-kit to that file and adds 120 toDRAWABLE_CONGRESSES(districtGeo.js:12), every 120-tagged map draws as a solid rectangle, andgeoCentroidputs the labels in the wrong place.filterStateDistricts(districtGeo.js:59) checksCDSESSNbut not winding. AgeoArea(f) < 2 * Math.PIcheck (or a rewind) there makes the step safe whatever ui-kit ships. - The PR body says that
districtGeo.test.jshas 13 tests. Vitest runs 12. Update the body. - The dataset source has no pinned revision.
us-data-cd119(scripts/compute_impacts.py:148) hasrevision: None, so it downloads the latest Hugging Face file. It records the installedpolicyengine-us-dataversion, not the version of the file. This is the same as before the PR. A pinned revision gives a true record of the boundary plan. - The card-view region names are fixed text (for example AL "Birmingham & Black Belt"). They come from an older plan. When the card view becomes the 120th fallback, these names can be wrong for redrawn states.
What I checked
- Every changed line in the 6 files. The Congress comes from
impactsByYear[year].districtCongresswhen a year is selected, and frommodel_notes.district_congresswhen no year is selected. Each falls back to 119. A year does not borrow the root tag.ReformAnalyzerwarms the same Congress thatDistrictMapopens on.DataContext.jsxpassesmodel_notesandimpacts_by_yearthrough, so the tags reach the map. - Writer side: single-year, multi-year and offline (
--output) records all carry the tag. A multi-year write replaces the root tag with the tag of the latest write, and that write also sets the rootdistrict_impactscolumn, so the two stay together. Thepublish-reform.ymlworkflow uses the offline path with the default source, so new analyses get tag 119. - The 119th premise:
make_block_cd_distributions.pyin policyengine-us-data calledfetch_block_to_district_map(119)in every version since it was added on January 26, 2026. It normalizes at-large districts to01. - ui-kit 0.9 boundary file: 437 features (435 districts, DC, PR), all
CDSESSN119, allgeoArea < 2π(largest 0.038 sr). District counts per state matchSTATE_DISTRICTSincompute_impacts.py.DISTRICT_ID"NC-01" becomes the key "NC-1", which is the key thatcompute_district_impactswrites. Single-district states never reach the map. - ui-kit#41 120th file: all 437 features are inverted (this confirms the ui-kit#41 review). This PR cannot load that file today.
- Rendering in jsdom with mocked data: NC untagged and NC tagged 119 draw 14 district shapes, 14 labels and the header "119th Congress districts". A multi-year analysis (2026 untagged, 2027 tagged 120) draws 119th boundaries for 2026 and falls back for 2027. AL tagged 120 crashes (Finding 1).
- Tests (vitest): main 52 passed. Head 43 passed (the branch is older than main). Test merge with main 64 passed, which includes 12 new
districtGeotests. Python:test_compute_impacts_datasets.py8 passed.test_auto_triage.pycannot be collected withouthypothesis, and this is not related to the PR. - Lint: no errors at main, head and the test merge. The warnings go from 10 to 9. The project has no typecheck (it is JavaScript).
- Build:
next buildpasses at main, head and the test merge. The first page load does not change (635 KB of scripts). The Districts chunk grows from 62 KB to 88 KB gzipped. The 119th boundary file is a separate 243 KB gzipped chunk that loads when the Districts code runs. The ui-kit lazy loaders also add about 23 MB of static chunks (state legislative boundaries, UK maps) to the build output. Pages do not load these chunks. - Mergeable state: GitHub says MERGEABLE and CLEAN. Main moved 11 commits (rate-limit work, last commit on 2026-11-13 2:51pm EST). These commits touch
ReformAnalyzer.jsx, and the merge resolves automatically. - CI: the PR has no status checks. No workflow runs tests on pull requests in this repo.
- Overlap: open PRs #111 and #149 also change
scripts/compute_impacts.py. Both are stale (last updated in February and March 2026) and already conflict with main. #111 conflicts with this PR incompute_impacts.py. - Comments: one author comment (2026-11-13 2:39pm EST) with a browser check of NC, NY and GA. No reviews. The linked items are ui-kit#41 (open, REQUEST_CHANGES) and microcosm#1526 (open).
Not verified
- I did not run the app against production data. The app needs
NEXT_PUBLIC_SUPABASE_ANON_KEY, and I did not use a key. Rendering evidence comes from a jsdom render test with mocked data. - I did not check that the published
states/XX.h5files on Hugging Face were built with the 119th block assignments. I checked only the source script. Analyses from before January 26, 2026 used older files with a possibly different district assignment, and the 119 default can be wrong for them. - I did not compare district shapes in a real browser or check the 118th vs 119th redraw list (AL, GA, LA, NC, NY) against ArcGIS.
- I did not run
compute_impacts.pyend to end (no microsimulation).
…ing; pin the state files - The card fallback read yearImpacts, which only GenericStateDistrictMap defines, so a 120-tagged analysis in AL, AZ, OK, SC or UT blanked the page, and other states said "District data not available". It now takes the shown year's results and Congress, lists every district in them, and says why there's no map. The fixed district list and its region names (from an older map) are gone. The header's click hint shows only when the map can be drawn. - filterStateDistricts rewinds any feature with an area over a hemisphere, so an inverted boundary file can't fill the map. - us-data-cd119 is pinned to the Hugging Face revision current today (last commit 2026-05-31), and model_notes records it as district_dataset_revision beside district_congress. Tests: render tests for the fallback (AL, NC, a selected year, a failed load, no results), rewind tests, and revision tests in Python. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @PavelMakarchuk. Everything is addressed in Should address: the fallback.
Suggestions
Lint has no errors and the same 9 warnings. |
ui-kit 0.15.0 (PolicyEngine/policyengine-ui-kit#41) ships the 120th Congress boundaries, so analyses tagged 120 now draw on them instead of falling back to the district list. Other Congresses still fall back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at c890669
| Previous item (review at 9e722f3) | Severity | Status | Evidence |
|---|---|---|---|
1. The 120th fallback crashes (yearImpacts ReferenceError) or hides the data |
Should address | Fixed | DistrictMap.jsx:138 takes yearImpacts and congress as props, and :854 passes them. eslint --rule '{"no-undef":"error"}' finds 0 errors. The 5 new fallback tests pass at head. They fail with ReferenceError: yearImpacts is not defined when I put back the old DistrictMap.jsx. |
| S1. Guard against inverted rings | Suggestion | Fixed | districtGeo.js:67 (rewindIfInverted), applied at :95, with 3 tests. Also, the ui-kit 0.15.0 files have 0 of 437 inverted features for both the 119th and the 120th. |
| S2. Test count in the PR body | Suggestion | Fixed | The body says 16 + 6 + 10 tests and 74 in the full suite. Vitest runs 74, and pytest runs 10. |
| S3. Pin the dataset revision | Suggestion | Fixed | scripts/compute_impacts.py:155 pins 21280dca. This is the current Hugging Face head, and it has all 51 states/*.h5 files. The revision goes into model_notes.district_dataset_revision and into each year. |
| S4. Region names in the card view | Suggestion | Fixed | The fixed STATE_DISTRICTS list is gone. The card view shows "District N" from the results. |
All items of the previous review are fixed. The new commits also bump ui-kit to 0.15.0 and add the 120th Congress to DRAWABLE_CONGRESSES. ui-kit#41 merged on November 24 at 2:18pm EST, and 0.15.0 was published at 2:31pm EST. With the real ui-kit files, the map draws the correct number of districts for the 119th and the 120th. Build, lint and tests pass.
Verdict: APPROVE
Suggestions
- The header still says "Click on a district" after a failed map load. The author comment says that the hint shows only when the map can be drawn. But
DistrictMap.jsx:1181checks onlyDRAWABLE_CONGRESSES.includes(congress), and the load error is known only insideGenericStateDistrictMap.- Input: a GA analysis tagged 120 (or an untagged analysis), and the boundary chunk fails to load.
- Expected: the header has no "Click on a district" hint, because there is no map.
- Actual: the header says "120th Congress districts (from January 3, 2027). Click on a district to see detailed impact analysis". The body says "The district map didn't load, so results are listed by district."
- Fix: send the load state up to the header, or show the hint inside
GenericStateDistrictMaponly when it draws the map. The NC failed-load test inDistrictMap.test.jsxcan also check that the hint is not shown.
What I checked
- The diff
9e722f3..c890669. Most of the diff is the merge with main (adcbfa9: dashboard API and rate-limit work). The PR's own changes are in52756fcandc890669(8 files). - Tests (vitest): 74 passed in 7 files. This includes 16
districtGeotests and 6DistrictMaprender tests. Python:scripts/test_compute_impacts_datasets.py10 passed. - Lint: 0 errors and 9 warnings, the same warnings as before.
- Build:
next buildpasses. The 119th boundary file (243 KB gzipped) and the 120th boundary file (218 KB gzipped) are separate lazy chunks. - Real boundary files: I loaded the ui-kit 0.15.0 files through
filterStateDistricts. Both files have 437 features with oneCDSESSNeach (119 or 120). The 120th district counts per state are the same as the 119th counts. Every feature has a district number, and no feature is inverted. - Real render in jsdom (with the real ui-kit loader): NC, AL, UT, TX and CA draw 14, 7, 4, 38 and 52 district shapes for both the 119th and the 120th. None of them falls back to the list.
- Fallback: a Congress that the app cannot draw (121) lists the districts with the "aren't available in this app yet" note and does not call the loader. A failed load lists all districts with the "didn't load" note.
- ui-kit 0.9 to 0.15: the tracker imports only
theme.cssandloadCongressionalDistrictsGeo. The theme changes--text-tertiaryand adds--text-5xlto--text-9xl. The tracker does not use these tokens. - Writer side: single-year, multi-year and offline records carry
district_congressanddistrict_dataset_revision. A multi-year write removes the old root revision before it adds the new one, so the root tag and the root results stay together. - Hugging Face: the pinned revision
21280dcais the current head (last commit May 31, 2026).states/NC.h5resolves at that revision. - Mergeable state: MERGEABLE and CLEAN. The PR has no status checks, because no workflow runs on pull requests in this repo. Open PRs #111 and #149 also change
compute_impacts.py, but both are stale (February and March 2026). #229 does not change the same code.
Not verified: I did not run the app in a browser against production data. No production analysis is tagged 120 yet.
The header showed "Click on a district" for any drawable Congress, even while the boundaries loaded or after they failed to load. The map now reports whether it drew, and the header shows the hint only then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @PavelMakarchuk. I took your suggestion in
Tests (74), lint (0 errors, same 9 warnings) and |
Summary
The Districts tab draws ArcGIS's 118th Congress district layer. Every state analysis, though, runs on the policyengine-us-data state files, which assign households to 119th Congress districts (
make_block_cd_distributions.pycallsfetch_block_to_district_map(119)). Five states redrew between the 118th and 119th Congresses (Alabama, Georgia, Louisiana, North Carolina and New York), so in those states the published district results sit on the wrong boundaries today.This PR draws each analysis on the boundaries it was computed on, and records that Congress with every analysis. It also bumps ui-kit to 0.15.0, which has the 120th Congress boundaries, so moving the tracker to the 120th for the 2027 sessions then takes two steps: add a dataset source and recompute. Nine states redrew for the 120th: AL, CA, FL, LA, NC, OH, TN, TX and UT.
Changes
Map (
DistrictMap.jsx,ReformAnalyzer.jsx, newdistrictGeo.js)loadCongressionalDistrictsGeoinstead of ArcGIS, filtered to the state byDISTRICT_ID.model_notes.district_congress, or from a year's owndistrictCongressin multi-year analyses. Untagged analyses default to 119, which is what every existing analysis used.@policyengine/ui-kitfrom 0.9.0 to 0.15.0, which adds the 120th boundaries (Add 120th Congress district maps and tables policyengine-ui-kit#41), so analyses tagged 119 or 120 draw on their own boundaries. Nothing else the tracker uses from ui-kit changed between those versions: it only importstheme.cssand the districts loader.CDSESSNcatches a file from the wrong Congress, since ui-kit loads the 119th file for a Congress it doesn't have.Compute (
scripts/compute_impacts.py)STATE_DATASETS, chosen with--state-datasetorTRACKER_STATE_DATASET. Each source says which Congress's districts it uses. The default,us-data-cd119, is the current files, so existing runs don't change.model_notes.district_congress, plusdistrict_dataset_revision, the Hugging Face revision of the state file. Multi-year analyses also tag each year.us-data-cd119is pinned to revision21280dca(the repo's head on November 24, 2026; last commit May 31), so every run reads the same files.state_fips * 100 + 1..n.populace-us, as the offline path already did.Path to the 120th Congress
DRAWABLE_CONGRESSES.STATE_DATASETSentry for the microcosm release that assigns households to 120th districts. Tracked in Move congressional districts to the 120th Congress microcosm#1526.Testing
next buildpasses, and the boundary file builds as its own lazy-loaded chunk.src/components/reform/districtGeo.test.js: 16 tests covering Congress selection, labels, district parsing, state filtering, loading the 119th and 120th, refusing other Congresses, and rewinding.src/components/reform/DistrictMap.test.jsx: 6 render tests. One checks that an analysis tagged 120 loads and draws the 120th boundaries. Five cover the fallback: a Congress the app can't draw, a failed 120th load, a selected year's results, a failed 119th load and an analysis without district results. The fallback tests fail on the component before52756fcwithReferenceError: yearImpacts is not defined, and the 120 tests fail without 120 inDRAWABLE_CONGRESSES.loadStateDistrictsGeo, every state's 120th districts load, match the 119th district counts, are numbered 1 to N (or at-large) and have no inverted rings.scripts/test_compute_impacts_datasets.py: 10 tests covering source selection, the pinned revision, and the tags in single-year, multi-year and no-district writes, with a fake Supabase client.🤖 Generated with Claude Code