From fdabb55b6c1433e221eee9f51fd66350470e4056 Mon Sep 17 00:00:00 2001 From: Brian Fuller Date: Thu, 13 Nov 2025 12:52:24 -0700 Subject: [PATCH 1/2] Modifications to fix school districts returning None. Added fields to match api fields --- src/geocodio/client.py | 18 ++++++++++++++---- tests/e2e/test_api.py | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/geocodio/client.py b/src/geocodio/client.py index b74cf2e..706ec61 100644 --- a/src/geocodio/client.py +++ b/src/geocodio/client.py @@ -438,10 +438,20 @@ def _parse_fields(self, fields_data: dict | None) -> GeocodioFields | None: school_districts = None if "school" in fields_data: - school_districts = [ - SchoolDistrict.from_api(district) - for district in fields_data["school"] - ] + school_data = fields_data["school"] + if isinstance(school_data, dict): + school_districts = [ + SchoolDistrict.from_api(district) + for district in school_data.values() + ] + elif "school_districts" in fields_data: + school_data = fields_data["school_districts"] + if isinstance(school_data, dict): + school_districts = [ + SchoolDistrict.from_api(district) + for district in school_data.values() + ] + # Dynamically parse all census fields (e.g., census2010, census2020, census2024, etc.) # This supports any census year returned by the API diff --git a/tests/e2e/test_api.py b/tests/e2e/test_api.py index ac7b818..d48578c 100644 --- a/tests/e2e/test_api.py +++ b/tests/e2e/test_api.py @@ -252,8 +252,14 @@ def test_integration_with_school_districts(client): assert isinstance(district.district_number, str) if district.lea_id: assert isinstance(district.lea_id, str) + if district.lea_code: #added to match actual api response + assert isinstance(district.lea_code, str) if district.nces_id: assert isinstance(district.nces_id, str) + if district.grade_low: #added to match actual api response + assert isinstance(district.grade_low, str) + if district.grade_high: #added to match actual api response + assert isinstance(district.grade_high, str) def test_integration_with_census2023(client): From 14ee69f762f600087b853a233fd95a9fcbdfa1f8 Mon Sep 17 00:00:00 2001 From: Brian Fuller Date: Thu, 13 Nov 2025 12:56:57 -0700 Subject: [PATCH 2/2] adds fields to model to represent fields returned by api --- src/geocodio/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/geocodio/models.py b/src/geocodio/models.py index 32ad22b..c707c40 100644 --- a/src/geocodio/models.py +++ b/src/geocodio/models.py @@ -140,7 +140,10 @@ class SchoolDistrict(ApiModelMixin): name: str district_number: Optional[str] = None lea_id: Optional[str] = None # Local Education Agency ID + lea_code: Optional[str] = None # Local Education Agency Code nces_id: Optional[str] = None # National Center for Education Statistics ID + grade_low: Optional[str] = None # Lowest grade served + grade_high: Optional[str] = None # Highest grade served extras: Dict[str, Any] = field(default_factory=dict, repr=False)