Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16108,7 +16108,8 @@ def nasa_data_granules_to_gdf(

df = pd.json_normalize([dict(i.items()) for i in granules])
df.columns = [col.split(".")[-1] for col in df.columns]
df = df.drop("Version", axis=1)
if "Version" in df.columns:
df = df.drop("Version", axis=1)
Comment on lines +16111 to +16112

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.

def get_bbox(rectangles):
xmin = min(rectangle["WestBoundingCoordinate"] for rectangle in rectangles)
Expand Down Expand Up @@ -16136,9 +16137,10 @@ def get_polygon(coordinates):
elif "GPolygons" in df.columns:
df["geometry"] = df["GPolygons"].apply(get_polygon)

gdf = gpd.GeoDataFrame(df, geometry="geometry")

gdf.crs = crs
if "geometry" in df.columns:
gdf = gpd.GeoDataFrame(df, geometry="geometry", crs=crs)
else:
gdf = gpd.GeoDataFrame(df)

Comment on lines +16140 to 16144

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
if output is not None:
for column in gdf.columns:
Expand Down
Loading