Skip to content

Chunk long ucgid lists and handle 204 in group() fetch (v0.6.6) - #10

Merged
jinskeep-morpc merged 3 commits into
mainfrom
fix/group-fetch-ucgid-chunking
Sep 30, 2026
Merged

jinskeep-morpc merged 3 commits into
mainfrom
fix/group-fetch-ucgid-chunking

Conversation

@jinskeep-morpc

Copy link
Copy Markdown
Collaborator

Summary

CensusAPI with group= failed for large hierarchical geography requests, e.g. CensusAPI(Endpoint('dec/pl', 2020), 'region15', group='P1', sumlevel='070').

  • Chunk long ucgid lists in _fetch_group(). Sumlevels that can't use pseudo() (like 070) are resolved to an explicit ucgid list. _fetch_variables() already sent it in chunks of 100, but _fetch_group() sent it in one URL (~15k characters for region15 at 070), and the Census API drops the connection past ~8k (ConnectionError: RemoteDisconnected). The chunking is now a shared _ucgid_chunks() helper used by both paths.
  • Treat 204 No Content as no rows in _fetch_group(), matching _fetch_variables() since 0.6.5. Chunks with no data are skipped with a warning; if every chunk is empty the result has no rows (e.g. dec/pl publishes no 070 data). Other HTTP errors still raise.
  • CHANGELOG.md (0.6.6) and reference/dev_notes.md updated.

Testing

  • 5 new tests in tests/test_api.py (TestFetchGroupChunking); 352 passing locally. The chunking test fails against the old _fetch_group().
  • Live: a 627-GEOID group(P1) request against 2020 dec/dhc that previously disconnected now returns data in 7 requests; 2020 dec/pl P1 for Franklin at 070 now returns an empty long with a warning instead of raising HTTPError.

🤖 Generated with Claude Code

jinskeep-morpc and others added 3 commits September 30, 2026 11:38
_fetch_group sent the full hierarchical ucgid list in one URL, so large
requests (e.g. region15 at sumlevel 070, ~15k chars) failed with
RemoteDisconnected. Move the chunking from _fetch_variables into a shared
_ucgid_chunks helper and use it in both fetch paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_fetch_group raised HTTPError on 204, so group= requests for geographies
without data (e.g. dec/pl at sumlevel 070) failed, and with ucgid
chunking a single empty chunk would stop the whole fetch. Skip 204
chunks with a warning, as _fetch_variables does, and return an empty
frame with the group's columns when every chunk is empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jinskeep-morpc
jinskeep-morpc merged commit c03e2ae into main Sep 30, 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