Skip to content

Add map_columns for renaming CRM export headers - #231

Merged
shivamlalakiya merged 1 commit into
mainfrom
e1-map-columns
Sep 25, 2026
Merged

shivamlalakiya merged 1 commit into
mainfrom
e1-map-columns

Conversation

@shivamlalakiya

Copy link
Copy Markdown
Contributor

Summary

A no-code upload flow (column-mapping UI over an arbitrary CRM export) needs a way to rename whatever headers a user's file happens to have to the canonical names the ingest functions expect, and to fail loudly and completely if the mapping the user picked is missing something required.

philanthropy.ingest.map_columns(df, mapping, *, required=()) renames columns per the mapping (unmapped columns pass through unchanged, mapping keys not present in df.columns are ignored) and raises one ValueError listing every still-missing required column, rather than surfacing a KeyError for the first missing field a caller happens to touch.

Test plan

  • python -c "from philanthropy.ingest import map_columns; print('OK')"
  • tests/test_map_columns.py: rename + pass-through, unknown mapping keys ignored, required columns present passes, missing required columns raises one error naming all of them, no-required-columns never raises, input frame not mutated
  • make ci (flake8, mypy, doctest, full suite, 92% coverage floor) - all green
  • make riskcov (risk-tier floor over preprocessing/, models/, ingest/, cli.py) - green

A no-code upload flow lets a user choose which of their own column
headers means "donor ID" or "gift date" without ever showing the library
the original names. map_columns applies that mapping and checks the
result has every column the next ingest step needs, raising one error
that lists every missing column instead of failing on the first one a
caller happens to touch.
@shivamlalakiya
shivamlalakiya merged commit 0c79e40 into main Sep 25, 2026
15 checks passed
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.

1 participant