-
Notifications
You must be signed in to change notification settings - Fork 132
Migrate multiple scripts to DC V2 clients and tighten tests #1861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rohitkumarbhagat
merged 13 commits into
datacommonsorg:master
from
rohitkumarbhagat:sg-deprecate-pyclient-1
Feb 5, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9841bb6
Use V2 sparql in facility download
rohitkumarbhagat a042955
Migrate rff raster to v2 client
rohitkumarbhagat fd750dd
Migrate earthengine utils to DC V2 wrapper
rohitkumarbhagat 302b4a8
removed unused datacommons reference from tools/statvar_importer/mcf_…
rohitkumarbhagat c0878f8
remived unused datacommons reference from scripts/us_epa/parent_compa…
rohitkumarbhagat 8583727
removed unused reference from tools/statvar_importer/place/place_reso…
rohitkumarbhagat 15eb333
Migrate enhanced TMCF DC API usage
rohitkumarbhagat 317902d
Use module-qualified test calls
rohitkumarbhagat 44c7bc0
Update scripts/earthengine/utils.py
rohitkumarbhagat 29fe792
Refactor geojson extraction in get_county_geoid
rohitkumarbhagat 23158f3
Update scripts/earthengine/utils.py
rohitkumarbhagat 5360c1d
Refactor node property helpers
rohitkumarbhagat 8ecfc47
Merge branch 'master' into sg-deprecate-pyclient-1
rohitkumarbhagat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ netCDF4 | |
| protobuf | ||
| rasterio | ||
| rdp | ||
| requests-mock | ||
| s2sphere | ||
| sentence-transformers | ||
| tabula-py | ||
|
|
||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import sys | ||
| from pathlib import Path | ||
| import types | ||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| sys.path.insert(0, str(REPO_ROOT)) | ||
|
|
||
| if "osgeo" not in sys.modules: | ||
| osgeo_module = types.ModuleType("osgeo") | ||
| gdal_module = types.ModuleType("gdal") | ||
| osgeo_module.gdal = gdal_module | ||
| sys.modules["osgeo"] = osgeo_module | ||
| sys.modules["osgeo.gdal"] = gdal_module | ||
|
|
||
| from scripts.rff import preprocess_raster | ||
|
|
||
|
|
||
| class FakeNodeEndpoint: | ||
|
|
||
| def __init__(self, place_children): | ||
| self._place_children = place_children | ||
|
|
||
| def fetch_place_children(self, place_dcids, children_type, as_dict): | ||
| return {"country/USA": self._place_children} | ||
|
|
||
| def fetch_property_values(self, node_dcids, properties): | ||
| raise AssertionError("fetch_property_values should not be called") | ||
|
|
||
|
|
||
| class FakeClient: | ||
|
|
||
| def __init__(self, node): | ||
| self.node = node | ||
|
|
||
|
|
||
| class PreprocessRasterTest(unittest.TestCase): | ||
|
|
||
| def test_get_county_geoid_dp1(self): | ||
| county = "geoId/06085" | ||
| geojson = ( | ||
| '{"type":"Polygon","coordinates":[[[0,0],[0,2],[2,2],[2,0],[0,0]]]}' | ||
| ) | ||
| dp1_properties = { | ||
| county: { | ||
| "arcs": { | ||
| "geoJsonCoordinatesDP1": { | ||
| "nodes": [{ | ||
| "value": geojson | ||
| }], | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| node = FakeNodeEndpoint(place_children=[{"dcid": county}]) | ||
| client = FakeClient(node) | ||
| with mock.patch.object(preprocess_raster, | ||
| "get_datacommons_client", | ||
| return_value=client), mock.patch.object( | ||
| preprocess_raster, | ||
| "dc_api_batched_wrapper", | ||
| return_value=dp1_properties) as mock_wrapper: | ||
| result = preprocess_raster.get_county_geoid(1.0, 1.0) | ||
| self.assertEqual(result, county) | ||
| self.assertEqual(mock_wrapper.call_count, 1) | ||
|
|
||
| def test_get_county_geoid_fallback(self): | ||
| county = "geoId/06085" | ||
| geojson = ( | ||
| '{"type":"Polygon","coordinates":[[[0,0],[0,2],[2,2],[2,0],[0,0]]]}' | ||
| ) | ||
| dp1_properties = { | ||
| county: { | ||
| "arcs": { | ||
| "geoJsonCoordinatesDP1": { | ||
| "nodes": [], | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| fallback_properties = { | ||
| county: { | ||
| "arcs": { | ||
| "geoJsonCoordinates": { | ||
| "nodes": [{ | ||
| "value": geojson | ||
| }], | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| node = FakeNodeEndpoint(place_children=[{"dcid": county}]) | ||
| client = FakeClient(node) | ||
| with mock.patch.object(preprocess_raster, | ||
| "get_datacommons_client", | ||
| return_value=client), mock.patch.object( | ||
| preprocess_raster, | ||
| "dc_api_batched_wrapper", | ||
| side_effect=[ | ||
| dp1_properties, fallback_properties | ||
| ]) as mock_wrapper: | ||
| result = preprocess_raster.get_county_geoid(1.0, 1.0) | ||
| self.assertEqual(result, county) | ||
| self.assertEqual(mock_wrapper.call_count, 2) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.