Repository navigation
Collect ACS margins of error (redo of #173) - #177
Merged
Merged
Conversation
The B-table scrapers (demographics, economic, education, housing) kept Census annotation codes such as -666666666 as real numbers and filled missing components with 0 before summing. Tiny towns like Averill and Glastenbury ended up with a median household income of -666,666,666, and a sum could include a sentinel or skip a missing part. Negative estimates are now missing, and a sum with any missing component is null rather than partial. Also points test_base.py at data_collection.base; it imported the deleted data_collection_OLD and could not be collected.
The B-table scrapers fetched only estimates. They now request each table with group(), which returns every estimate and margin of error and stays under the API's 50-variable limit (B01001 alone needs 49 codes), and each tidy row gains Value_MOE and Percent_MOE (percentage points). Margins follow the Census approximations: root sum of squares for sums, counting only the largest margin among zero estimates, and the proportion formula for percents, with the ratio form when the term under the root is negative or zero (a 100% share). -555555555 margins count as zero; other negative codes are missing.
group(DPxx) already returns each estimate's margin (M) and each percent's margin (PM), but the profile variables.json lists only E and PE codes, so the tidy merge dropped them. Each tidy row now carries its margin as MOE. They're a column rather than rows of their own so that selectors on Measure (e.g. ILIKE 'Percent%') don't pick them up.
duaneatat
requested review from
FWJK1 and
iansargent
and removed request for
iansargent
November 2, 2026 15:59
iansargent
approved these changes
Nov 3, 2026
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.
This is the same change Ian approved in #173, unchanged. #173 merged into its stacked base branch (
db/backend-test-suite) instead of main, so its commits never reached main. This PR puts the same four commits on main; the only addition is a merge of main to bring the branch up to date. See #173 for the description.