Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts NASA Earthdata granule-to-GeoDataFrame conversion to avoid errors when optional fields are missing in the returned metadata.
Changes:
- Guarded removal of the
Versionfield to avoidKeyErrorwhen absent. - Made GeoDataFrame construction conditional on presence of a
geometrycolumn (bounding rectangles/polygons).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if "Version" in df.columns: | ||
| df = df.drop("Version", axis=1) |
There was a problem hiding this comment.
This change adds new edge-case handling (missing "Version" column; missing geometry inputs). There are existing unit tests for leafmap.common (tests/test_common.py), but none cover the NASA Earthdata helpers. Please add tests that validate nasa_data_granules_to_gdf() does not raise when "Version" is absent and that the no-geometry case is handled in a defined way (e.g., raises a specific error or returns a DataFrame).
| if "geometry" in df.columns: | ||
| gdf = gpd.GeoDataFrame(df, geometry="geometry", crs=crs) | ||
| else: | ||
| gdf = gpd.GeoDataFrame(df) | ||
|
|
There was a problem hiding this comment.
When neither "BoundingRectangles" nor "GPolygons" exists, this now returns a GeoDataFrame without an active geometry column (and without CRS). That conflicts with the function’s contract ("Converts … to a GeoDataFrame") and can break callers expecting gdf.geometry/gdf.crs, and to_file() will not be able to write geospatial formats without a geometry column. Consider raising a clear ValueError in this branch (optionally suggesting the required fields), or returning a plain pandas DataFrame / providing a non-geospatial export path when output is set.
| if "geometry" in df.columns: | |
| gdf = gpd.GeoDataFrame(df, geometry="geometry", crs=crs) | |
| else: | |
| gdf = gpd.GeoDataFrame(df) | |
| if "geometry" not in df.columns: | |
| raise ValueError( | |
| "Unable to construct a GeoDataFrame from granules: expected either " | |
| "'BoundingRectangles' or 'GPolygons' fields in the input to derive " | |
| "geometry. The resulting table has no 'geometry' column." | |
| ) | |
| gdf = gpd.GeoDataFrame(df, geometry="geometry", crs=crs) |
|
🚀 Deployed on https://69800c71cba0de64861c55b5--opengeos.netlify.app |
No description provided.