Fix: Census field appends not included in response #13
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
Fixes #12 - Census field appends (like
census2024) were not being included in geocoding responses even though the raw JSON from the API included them.Problem
The
_parse_fields()method was hardcoding only three census years:census2010census2020census2023When users requested
census2024or any other census year, the data was returned by the API but not parsed into the response object.Solution
Implemented dynamic census field parsing:
Dynamic Detection: The parser now automatically detects any field matching the pattern
census+ digits (e.g.,census2024,census2025)Smart Filtering: Only parses census fields that are defined in the
GeocodioFieldsmodel to maintain type safetyFuture-Proof: Adding support for new census years only requires adding a single line to the
GeocodioFieldsdataclass - no changes to parsing logic neededChanges
src/geocodio/client.py: Replaced hardcoded census parsing with dynamic detectionsrc/geocodio/models.py: Removedslots=TruefromGeocodioFieldsto allow dynamic field passing (backwards compatible)tests/unit/test_geocode.pyto verify all census fields are parsedBackwards Compatibility
✅ No breaking changes
slots=Truehas negligible performance/memory impact (~56 bytes per instance)Testing
Example Usage