Skip to content

USFEMA_FloodInsuranceClaims - #2177

Open
kartik-s21 wants to merge 43 commits into
datacommonsorg:masterfrom
kartik-s21:fema-download-fix
Open

USFEMA_FloodInsuranceClaims#2177
kartik-s21 wants to merge 43 commits into
datacommonsorg:masterfrom
kartik-s21:fema-download-fix

Conversation

@kartik-s21

@kartik-s21 kartik-s21 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

This PR optimizes and stabilizes the data download pipeline for the FEMA NFIP Flood Insurance Claims import.

Key Changes

  1. Direct Bulk Download Support:

    • Added bulk_url support to download the full dataset (FimaNfipClaims.csv) directly from OpenFEMA as the primary method, significantly speeding up the download process.
    • Implemented automatic fallback to paginated API download if direct bulk download fails or returns empty.
  2. Error Handling & Fallback Visibility:

    • Explicitly raise exceptions upon bulk download failure so that fallback events are properly captured and logged with warnings.
    • Added fatal logging and exceptions on API chunk failures or incomplete downloads to prevent silent partial data ingestion.
  3. CSV Chunk Concatenation Fixes:

    • Improved binary chunk merging logic to ensure consistent newline endings across chunks.
    • Guarded chunk concatenation to prevent empty/header-only chunks from injecting blank lines into the merged CSV.
    • Ensured safe temporary directory management (exist_ok=True and cleanup in finally blocks).
  4. Testing & Coverage:

    • Added comprehensive unit tests in fema_download_test.py covering:
      • Record count retrieval and error handling.
      • Direct bulk download success flow.
      • Direct bulk download failure with fallback to API pagination.
      • Multi-chunk pagination and header-only chunk merging without blank lines.

Verification

  • Validation Report - link
  • CRA Report - link
  • Differ summary - link (All these deletions are expected and are from Source side changes)

@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 direct bulk download option for the FEMA NFIP claims dataset as a faster and more reliable alternative to API pagination, which remains as a fallback. It also increases the pagination page size, improves error handling, and refines CSV chunk merging. The review feedback highlights two key improvements: raising an exception on bulk download failures to ensure proper logging instead of a silent fallback, and adding a check to prevent writing empty newlines when a downloaded chunk contains only a header.

Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py Outdated
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py Outdated
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download_test.py Fixed
@kartik-s21
kartik-s21 requested a review from saanikaaa August 24, 2026 08:53
@balit-raibot
balit-raibot self-requested a review August 25, 2026 11:05
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py Outdated
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py Outdated
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
Comment thread statvar_imports/fema/flood_insurance_claims/fema_download.py
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.

4 participants