refactor: Extract geo+vectors fetch and merge into dedicated functions#7
Open
dshkol wants to merge 1 commit intorefactor/dataframe-processingfrom
Open
refactor: Extract geo+vectors fetch and merge into dedicated functions#7dshkol wants to merge 1 commit intorefactor/dataframe-processingfrom
dshkol wants to merge 1 commit intorefactor/dataframe-processingfrom
Conversation
f7955c0 to
13ef466
Compare
d04cbe0 to
ae612c1
Compare
13ef466 to
1a67981
Compare
Extract the complex hybrid geo+vectors logic (~70 lines) from get_census()
into two dedicated helper functions:
1. _fetch_census_with_geometry_and_vectors():
- Handles the CensusMapper API quirk where geo.geojson doesn't return
vector data properly
- Makes separate calls to geo.geojson and data.csv endpoints
- Orchestrates the merge of geometry and vector data
2. _merge_geo_and_csv_results():
- Merges GeoDataFrame with CSV DataFrame on geographic identifier
- Detects common merge keys (GeoUID, id, rgid) automatically
- Falls back to index-based merge if no common key found
- Handles duplicate key cleanup after merge
This improves:
- Readability: get_census() main flow is now much simpler
- Testability: merge logic can be unit tested in isolation
- Single responsibility: each function has one clear purpose
- Documentation: detailed docstrings explain the API quirk
Added 2 new unit tests:
- test_merge_on_geoid_key: verifies key-based merge
- test_merge_fallback_by_index: verifies index fallback
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58530e2 to
44e62ec
Compare
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.
Summary
Extract the complex hybrid geo+vectors logic (~70 lines) from
get_census()into two dedicated helper functions.Changes
Added two new functions:
_fetch_census_with_geometry_and_vectors()geo.geojsondoesn't return vector data properlygeo.geojsonanddata.csvendpoints_merge_geo_and_csv_results()GeoUID,id,rgid) automaticallySimplified
get_census()Why
get_census()main flow is now much simplerTest plan
test_merge_on_geoid_key: verifies key-based mergetest_merge_fallback_by_index: verifies index fallback🤖 Generated with Claude Code