Skip to content

Add new Commerce EDA USASpending import - #2171

Open
shvngisingh wants to merge 27 commits into
datacommonsorg:masterfrom
shvngisingh:commerce_eda_usaspending_import
Open

shvngisingh wants to merge 27 commits into
datacommonsorg:masterfrom
shvngisingh:commerce_eda_usaspending_import

Conversation

@shvngisingh

@shvngisingh shvngisingh commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

[PR #2171] Add Commerce_EDA_USAspending Dataset Import

1. Overview

Adds the automated weekly data import pipeline for Commerce_EDA_USAspending (statvar_imports/commerce_eda_usaspending), ingesting U.S. Economic Development Administration (EDA) federal investment assistance awards by state/territory and program from the official USAspending.gov REST API (https://api.usaspending.gov/api/v2/search/spending_by_award/).

  • Buganizer Issue: b/547801183
  • Companion Schema & Manifest CL: cl/982670020

2. Key Changes

  1. Data Acquisition & Processing (process.py):
    • Dynamically queries USAspending.gov /api/v2/search/spending_by_award/ across federal fiscal years 2012 through get_current_fiscal_year() (accounting for the October 1 federal fiscal year boundary).
    • Filters by awarding agency (Department of Commerce) and sub-agency (Economic Development Administration) across assistance award types (02, 03, 04, 05).
    • Deduplicates award records across pagination and fiscal-year boundaries by Award ID / generated_internal_id.
    • Maps CFDA / Assistance Listing numbers and descriptions to 11 EDA assistance programs plus aggregated Total (Amount_Investment and 11 program-specific Amount_Investment_<Program> StatisticalVariables).
    • Normalizes all 50 U.S. states, DC, and 7 outlying territories to standard geoId/{state_fips} DCIDs.
    • Retains only net-positive state-program-year obligations (with a fail-closed guard if no positive aggregations remain) and writes output atomically via a temporary .tmp file.
  2. Schema & Mapping (investment_pvmap.csv, investment_metadata.csv, investment_schema.mcf, manifest.json):
    • Defines PV mappings and statvar_dcid overrides aligned with canonical Google3 StatVar definitions.
    • Defines the 4 new InvestmentProgramEnum instances (DistressedAreaRecompetePilotProgram, RegionalTechnologyAndInnovationHubs, STEMTalentChallenge, ScienceAndResearchParkDevelopmentGrants).
    • Configures weekly cron schedule (30 05 * * 1), import_groups: ["frequent", "infrequent"], node_mcf: ["investment_schema.mcf", "output/*.mcf"], and provenance_url: "https://www.usaspending.gov/".
  3. Validation & Unit Tests (validation_config.json, process_test.py, test_data/, README.md):
    • Adds 3 custom validation rules (check_deleted_records_percent at 0.1% threshold, active_programs_freshness verifying all 12 StatVars with total_svs = 12 and cohort-aware MaxDate bounds, and non_negative_investment_amounts).
    • Adds 16 hermetic unit tests in process_test.py and sample fixtures in test_data/ (sample_awards.json, sample_output.csv) covering API pagination, deduplication, retry/failure handling, de-obligation filtering, all-non-positive award guards, dynamic fiscal year boundaries, territory mapping, and rounding.

3. Validation & Test Evidence

  • Unit Tests: 16 / 16 PASSED (pytest statvar_imports/commerce_eda_usaspending/process_test.py)
  • Import Validation (tools.import_validation.runner): 6 / 6 PASSED (2,695 observations across 58 states/territories and 12 StatisticalVariables, 2,703 total nodes, 0 missing refs, 0 lint errors, 0.0% deleted records).
  • Cloud Batch Job (datcom-infosys-dev): commerce-eda-usaspending-shvngisingh-20261009-172155 (commerce-eda-usasp-c45bf705-7412-4cf30, SUCCEEDED)
  • Staged Dev GCS Run: gs://datcom-import-test/statvar_imports/commerce_eda_usaspending/Commerce_EDA_USAspending/2026_10_09T10_24_52_712858_07_00

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new automated importer for U.S. Economic Development Administration (EDA) investment datasets sourced from USASpending.gov, including preprocessing scripts, configuration files, and documentation. Feedback on the changes suggests improving the robustness of the preprocessing script by raising exceptions on API failures, adding guard checks for date parsing, and removing redundant code that attempts to update a commented-out metadata field. Additionally, it is recommended to explicitly map the 'Total' category in the PV map to properly represent aggregation.

Comment thread statvar_imports/commerce_eda_usaspending/process.py Outdated
Comment thread statvar_imports/commerce_eda_usaspending/process.py Outdated
Comment thread statvar_imports/commerce_eda_usaspending/process.py
Comment thread statvar_imports/commerce_eda_usaspending/Investmentpvmap.csv Outdated
@shvngisingh
shvngisingh force-pushed the commerce_eda_usaspending_import branch 5 times, most recently from 63a311b to b78097b Compare August 21, 2026 13:19
@shvngisingh
shvngisingh force-pushed the commerce_eda_usaspending_import branch from b78097b to 68b26e6 Compare August 21, 2026 13:24
…tion, and complete MCF schema in Commerce EDA USASpending import
…deobligation consistency, validation config, and cap PR sample to 200 rows
…gative and observation checks in validation_config.json while keeping active_programs_freshness
Comment thread statvar_imports/commerce_eda_usaspending/counters/Investment_counters.csv Outdated
Comment thread statvar_imports/commerce_eda_usaspending/output/Investment_cleaned.csv Outdated
Comment thread statvar_imports/commerce_eda_usaspending/investment_metadata.csv
Comment thread statvar_imports/commerce_eda_usaspending/investment_pvmap.csv
Comment thread statvar_imports/commerce_eda_usaspending/Investmentpvmap.csv Outdated
Comment thread statvar_imports/commerce_eda_usaspending/process.py Outdated
Comment thread statvar_imports/commerce_eda_usaspending/validation_config.json
…mport)

- Correct CFDA 11.030 program name to 'Science and Research Park Development Grants'
- Add golden_summary_report.csv and golden_observations.csv with GOLDENS_CHECK validation rules
- Make active_programs_freshness validation rule dynamic using current year
- Clarify check_deleted_records_percent description
- Add counters/* and golden_data/*.csv to manifest.json source_files
- Add defensive file-size checks before atomic replace and empty results guard in process.py
- Remove duplicate OH entry in investment_pvmap.csv
- Update README.md output artifact names and program coverage
…mport)

- Deduplicate awards across multi-year queries by internal ID in process.py
- Regenerate golden_summary_report.csv from full production dataset covering all 58 places
- Add raw payload archival via input_files/* in manifest.json source_files
- Remove 59 redundant full state name mappings from investment_pvmap.csv
- Add investment_schema.mcf with explicit provisional schema enums and register in manifest.json
- Add deduplication unit tests in process_test.py
- Cap input_files/investment_cleaned.csv to 200 sample rows to prevent repository bloat
- Add --existing_schema_mcf=investment_schema.mcf to stat_var_processor.py execution in README.md
- Remove extraneous investment_output_stat_vars_schema.mcf output from README.md
- Request generated_internal_id explicitly in USAspending API fields payload
- Replace non-ASCII emoji in process.py logging with [SUCCESS]
- Add test assertion in process_test.py for generated_internal_id field projection
- Add PR_2171_DESCRIPTION.md with complete pre-merge checklist details
- Fix node_mcf in manifest.json by declaring investment_schema.mcf as separate import input
- Add ProgramPlanning and TechnicalAssistance to active_programs_freshness in validation_config.json
- Add spell_allow_words,recompete to investment_metadata.csv to eliminate error-spell-words
- Add MAX_PAGES_PER_FY threshold ceiling to fetch_usaspending_data in process.py
- Replace logging.fatal and unreachable return with logging.error and RuntimeError in process.py
- Fix StatVar DCID for CFDA 11.030 in PR_2171_DESCRIPTION.md
- Update unit tests in process_test.py for RuntimeError and pagination ceiling
- Fix node_mcf in manifest.json by declaring investment_schema.mcf as separate import input
- Add ProgramPlanning and TechnicalAssistance to active_programs_freshness in validation_config.json
- Add spell_allow_words,recompete to investment_metadata.csv to eliminate error-spell-words
- Add MAX_PAGES_PER_FY threshold ceiling to fetch_usaspending_data in process.py
- Replace logging.fatal and unreachable return with logging.error and RuntimeError in process.py
- Fix StatVar DCID for CFDA 11.030 in PR_2171_DESCRIPTION.md
- Update unit tests in process_test.py for RuntimeError and pagination ceiling
…d strip pvmap header delimiters

- Consolidate import_inputs in manifest.json to a single entry so ValidationRunner succeeds on input0
- Add copy_schema_to_output in process.py to emit investment_schema.mcf into output/ for output/*.mcf globbing
- Add unit test in process_test.py for copy_schema_to_output
- Strip trailing empty columns from investment_pvmap.csv header and date row
- Document output/investment_schema.mcf in README.md
copybara-service Bot pushed a commit to datacommonsorg/schema that referenced this pull request Oct 9, 2026
… schema enums and StatisticalVariables, add dataset entries to prod_dataset_info.textproto and data_sources.json, and add resolved MCF provenance definition.

1. Upstream Source Migration / Data Acquisition by U.S. Economic Development Administration (EDA):
   - Ingests federal investment assistance awards by state and program dynamically from the official USAspending REST API (U.S. Department of the Treasury / U.S. Department of Commerce - EDA):
     * Landing Page: https://www.usaspending.gov/
     * API Endpoint: https://api.usaspending.gov/api/v2/search/spending_by_award/
   - Ingests annual investment obligation amounts across 58 U.S. states, DC, and outlying territories from FY 2012 through Present across 11 EDA assistance programs and Total investments.

2. Data Preprocessing & StatVar Alignment:
   - Added automated weekly pipeline under statvar_imports/commerce_eda_usaspending (PR #2171: datacommonsorg/data#2171).
   - Maps EDA assistance programs to 12 StatisticalVariables (Amount_Investment and 11 program-specific Amount_Investment_<Program> variables, including 4 new canonical InvestmentProgramEnum values: DistressedAreaRecompetePilotProgram, RegionalTechnologyAndInnovationHubs, STEMTalentChallenge, and ScienceAndResearchParkDevelopmentGrants).
   - Normalizes state/territory codes to standard Data Commons FIPS place DCIDs (geoId/{state_fips}) across all 50 states, DC, and 7 territories.
   - Enforces automated quality gates via 3 custom rules in validation_config.json (check_deleted_records_percent with 0.1% threshold, active_programs_freshness SQL validator across all 12 StatVars with total_svs = 12, and non_negative_investment_amounts).

PiperOrigin-RevId: 982670020
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.

3 participants