Skip to content

Fix county subdivision part lookup and chunk long ucgid requests - #6

Merged
jinskeep-morpc merged 1 commit into
mainfrom
fix/hierarchical-cousub-parts
Sep 23, 2026
Merged

jinskeep-morpc merged 1 commit into
mainfrom
fix/hierarchical-cousub-parts

Conversation

@jinskeep-morpc

Copy link
Copy Markdown
Collaborator

Problem

CensusAPI(Endpoint('dec/dhc', 2020), 'region15', sumlevel=SumLevel('070'), ...) (county subdivision place/remainder parts) failed in two ways:

  1. The pseudo lookup added in Fix hierarchical geoinfo for sumlevels that don't nest in the scope #5 (0.6.3) read getattr(GeoIDFQ, geo) using the API's name. That fails for county subdivision, which GeoIDFQ calls cousub (AttributeError). It also gave every scope county the same list of children. That's right for places, which don't nest in counties, but for 070 it would pair every county with every county subdivision.
  2. The data request sent the whole ucgid list at once. For region15 070 that's 498 GEOIDs (about 12 KB), and the Census API drops the connection.

Change

  • geos.py: use SumLevel(geo).parts[-1] as the GeoIDFQ attribute, and give each parent row only the children that match it on shared fields (county for county subdivisions; only state for places).
  • api.py: _fetch_variables sends plain ucgid lists in chunks of 100. pseudo() predicates are unchanged.

Note: dec/pl doesn't publish 070 in any year. dec/dhc (2020) and dec/sf1 (2010, 2000) do.

Testing

  • New tests: 1 in tests/test_geos_hierarchical.py (each county is paired with its own subdivisions), and 2 in tests/test_api.py (a long ucgid list is chunked; a pseudo query is not). All three failed before the change. Full suite: 343 passed.
  • Live, region15 070:
    • 496 / 481 / 421 parts for 2020 / 2010 / 2000, covering all 237 MORPC-lookup 070 geographies each year.
    • Each county subdivision's parts sum to its dec/pl total (263 of 264 match exactly in 2020). The exceptions are parts of places that no longer exist.
  • CHANGELOG (0.6.4) and reference/dev_notes.md are updated.

🤖 Generated with Claude Code

The pseudo lookup added in 0.6.3 read GeoIDFQ attributes by API name,
which fails for "county subdivision" (cousub), and gave every scope county
every county subdivision. Pair each parent with the children it shares
fields with.

Also request plain ucgid lists in chunks of 100: the 498 place/remainder
parts (070) in region15 in one URL were dropped by the Census API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jinskeep-morpc
jinskeep-morpc merged commit 873a4dd into main Sep 23, 2026
5 of 7 checks passed
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.

1 participant