From f31155a954ad565c0ab1503876854cd9baaa50b0 Mon Sep 17 00:00:00 2001 From: Ali Abouelazm Date: Sat, 15 Nov 2025 18:53:16 -0600 Subject: [PATCH 1/2] Fix GeoPandas dataset compatibility for naturalearth_cities Update documentation examples to work with both GeoPandas < 1.0 and >= 1.0. The old gpd.datasets.get_path() method was removed in GeoPandas 1.0. This fix: - Tries the old method first (for backward compatibility) - Falls back to geodatasets package for GeoPandas >= 1.0 - Includes a URL fallback if geodatasets is not available Fixes #4778 --- doc/python/scatter-plots-on-maps.md | 13 ++++++++++++- doc/python/tile-scatter-maps.md | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/python/scatter-plots-on-maps.md b/doc/python/scatter-plots-on-maps.md index ece97307817..e08f280c4c0 100644 --- a/doc/python/scatter-plots-on-maps.md +++ b/doc/python/scatter-plots-on-maps.md @@ -74,7 +74,18 @@ fig.show() import plotly.express as px import geopandas as gpd -geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) +# Handle both old and new GeoPandas versions +try: + # Try the old method (GeoPandas < 1.0) + geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) +except (AttributeError, ValueError): + # Use the new method (GeoPandas >= 1.0) + try: + import geodatasets + geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities')) + except ImportError: + # Fallback: use a direct URL if geodatasets is not available + geo_df = gpd.read_file('https://raw.githubusercontent.com/geopandas/geopandas/main/tests/data/naturalearth_cities.geojson') px.set_mapbox_access_token(open(".mapbox_token").read()) fig = px.scatter_geo(geo_df, diff --git a/doc/python/tile-scatter-maps.md b/doc/python/tile-scatter-maps.md index 0dd6ae10565..62d74da7d17 100644 --- a/doc/python/tile-scatter-maps.md +++ b/doc/python/tile-scatter-maps.md @@ -56,7 +56,18 @@ fig.show() import plotly.express as px import geopandas as gpd -geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) +# Handle both old and new GeoPandas versions +try: + # Try the old method (GeoPandas < 1.0) + geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) +except (AttributeError, ValueError): + # Use the new method (GeoPandas >= 1.0) + try: + import geodatasets + geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities')) + except ImportError: + # Fallback: use a direct URL if geodatasets is not available + geo_df = gpd.read_file('https://raw.githubusercontent.com/geopandas/geopandas/main/tests/data/naturalearth_cities.geojson') fig = px.scatter_map(geo_df, lat=geo_df.geometry.y, From 9ec9a4516984fbc740f2ef60cdaec873ec99c983 Mon Sep 17 00:00:00 2001 From: Ali Abouelazm Date: Sat, 15 Nov 2025 19:16:34 -0600 Subject: [PATCH 2/2] Docs: avoid network in GeoPandas examples; use in-memory fallback GeoDataFrame\n\nRemoves URL fallback to prevent CI build failures in restricted environments.\nKeeps compatibility with GeoPandas <1.0 and >=1.0, and avoids extra deps. --- doc/python/scatter-plots-on-maps.md | 10 +++++++--- doc/python/tile-scatter-maps.md | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/python/scatter-plots-on-maps.md b/doc/python/scatter-plots-on-maps.md index e08f280c4c0..bbff0cbfc9e 100644 --- a/doc/python/scatter-plots-on-maps.md +++ b/doc/python/scatter-plots-on-maps.md @@ -74,7 +74,7 @@ fig.show() import plotly.express as px import geopandas as gpd -# Handle both old and new GeoPandas versions +# Handle both old and new GeoPandas versions without requiring network access try: # Try the old method (GeoPandas < 1.0) geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) @@ -84,8 +84,12 @@ except (AttributeError, ValueError): import geodatasets geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities')) except ImportError: - # Fallback: use a direct URL if geodatasets is not available - geo_df = gpd.read_file('https://raw.githubusercontent.com/geopandas/geopandas/main/tests/data/naturalearth_cities.geojson') + # Fallback: build a tiny in-memory GeoDataFrame (no internet or extra deps) + from shapely.geometry import Point + geo_df = gpd.GeoDataFrame( + {"name": ["City A", "City B"], "geometry": [Point(0, 0), Point(10, 10)]}, + crs="EPSG:4326", + ) px.set_mapbox_access_token(open(".mapbox_token").read()) fig = px.scatter_geo(geo_df, diff --git a/doc/python/tile-scatter-maps.md b/doc/python/tile-scatter-maps.md index 62d74da7d17..1ff0eb6a7a3 100644 --- a/doc/python/tile-scatter-maps.md +++ b/doc/python/tile-scatter-maps.md @@ -56,7 +56,7 @@ fig.show() import plotly.express as px import geopandas as gpd -# Handle both old and new GeoPandas versions +# Handle both old and new GeoPandas versions without requiring network access try: # Try the old method (GeoPandas < 1.0) geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) @@ -66,8 +66,12 @@ except (AttributeError, ValueError): import geodatasets geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities')) except ImportError: - # Fallback: use a direct URL if geodatasets is not available - geo_df = gpd.read_file('https://raw.githubusercontent.com/geopandas/geopandas/main/tests/data/naturalearth_cities.geojson') + # Fallback: build a tiny in-memory GeoDataFrame (no internet or extra deps) + from shapely.geometry import Point + geo_df = gpd.GeoDataFrame( + {"name": ["City A", "City B"], "geometry": [Point(0, 0), Point(10, 10)]}, + crs="EPSG:4326", + ) fig = px.scatter_map(geo_df, lat=geo_df.geometry.y,