Repository navigation
Collect ACS margins of error - #173
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.
iansargent
approved these changes
Oct 31, 2026
iansargent
left a comment
Collaborator
There was a problem hiding this comment.
This all looks great! Approving.
iansargent
added a commit
that referenced
this pull request
Nov 3, 2026
Collect ACS margins of error (redo of #173)
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.
First of a stacked set adding Census margins of error (MOE), split by ETL step: collection, cleaning, then frontend. It's based on #171, so review that first. This one only changes what we collect into the RAW lake tables. The cleaners select explicit columns, so they ignore the new columns until the cleaning PR. It also stops storing Census placeholder codes as real values: tiny towns like Averill had a median household income of -666,666,666.
group(), which includes every margin and stays under the API's 50-variable limit. Rows gainValue_MOEandPercent_MOE, using the Census formulas for sums and proportions (see the docstrings indata_collection/base.py).MOEcolumn. The profile variable list names only E and PE codes, so the M and PM codes were being dropped.test_base.pyimports fromdata_collectionagain, and the backend CI workflow now runs it.Closes #172