Treat 204 No Content as no rows; require morpc 0.7.5 (v0.6.5) - #9
Merged
Merged
Conversation
The Census API answers 204 when a request is valid but it has no data for the requested geographies. For example, ACS 5-year 2017 lists place/remainder parts (070) but publishes none, which stopped a whole workflow run. _fetch_variables now logs a warning and treats that request as zero rows; other HTTP errors still raise. Requires morpc 0.7.4, whose HTTPError carries the response. 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.
Problem
The Census API returns 204 No Content when a request is valid but it has no data for the requested geographies. ACS 5-year 2017 lists place/remainder parts (
070) in its geography list, but returns 204 for every070request, in both ucgid and for/in forms; other years and levels are fine. Since morpc 0.7.3 that raisedHTTPError, which stopped the wholeCensusAPIfetch and the morpc-pop-collect notebook run.Change
CensusAPI._fetch_variablescatches anHTTPErrorwhoseresponse.status_codeis 204, logs a warning, and treats that request as zero rows. If every request is empty,CensusAPI.longis an empty frame. Other HTTP errors still raise.HTTPError, which this fix relies on.morpc.reqlogs and errors (Redact API keys and tokens from morpc.req logs and errors morpc-py#207), completing the logging fix in Stop logging the Census API key in geoinfo_from_params #8.reference/dev_notes.mdentry.Testing
tests/test_api.py: a 204 chunk is skipped while the others are kept; an all-204 fetch returns an empty frame with the expected columns; a 400 still raises. The two 204 tests failed before the change.CensusAPI(Endpoint('acs/acs5', 2017), 'region15', sumlevel=SumLevel('070'), ...)returns an emptylongwith warnings, instead ofRuntimeError.🤖 Generated with Claude Code