Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
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
  • Loading branch information
Ali Abouelazm authored and Ali Abouelazm committed Nov 16, 2025
commit f31155a954ad565c0ab1503876854cd9baaa50b0
13 changes: 12 additions & 1 deletion doc/python/scatter-plots-on-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Comment on lines +84 to +85
Copy link
Member

@LiamConnors LiamConnors Nov 20, 2025

Choose a reason for hiding this comment

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

This dataset doesn't currently exist on geodatasets, so this will never be successful even with geopandas >=1.0

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,
Expand Down
13 changes: 12 additions & 1 deletion doc/python/tile-scatter-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down