Repository navigation
Chunk long ucgid lists and handle 204 in group() fetch (v0.6.6) - #10
Merged
Merged
Conversation
_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>
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.
Summary
CensusAPIwithgroup=failed for large hierarchical geography requests, e.g.CensusAPI(Endpoint('dec/pl', 2020), 'region15', group='P1', sumlevel='070')._fetch_group(). Sumlevels that can't usepseudo()(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._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/plpublishes no 070 data). Other HTTP errors still raise.CHANGELOG.md(0.6.6) andreference/dev_notes.mdupdated.Testing
tests/test_api.py(TestFetchGroupChunking); 352 passing locally. The chunking test fails against the old_fetch_group().group(P1)request against 2020dec/dhcthat previously disconnected now returns data in 7 requests; 2020dec/plP1 for Franklin at 070 now returns an emptylongwith a warning instead of raisingHTTPError.🤖 Generated with Claude Code