Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix GeoPandas dataset compatibility for naturalearth_cities #5420

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

Open
AliAbouelazm wants to merge 2 commits into plotly:main
base: main
Choose a base branch
Loading
from AliAbouelazm:fix-geopandas-dataset-compatibility

Conversation

@AliAbouelazm
Copy link

@AliAbouelazm AliAbouelazm commented Nov 16, 2025
edited by emilykl
Loading

Closes #5289

Update documentation examples to support both GeoPandas < 1.0 and >= 1.0.

Context: GeoPandas 1.0 removed the datasets accessor used in gpd.datasets.get_path("naturalearth_cities").

Changes:

  • Try old method first for backward compatibility
  • Fallback to geodatasets package for GeoPandas >= 1.0
  • Final fallback to a public GeoJSON URL if geodatasets is not available

Files updated:

  • doc/python/scatter-plots-on-maps.md
  • doc/python/tile-scatter-maps.md

Docs-only change.

Ali Abouelazm added 2 commits November 15, 2025 18:53
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 plotly#4778 
...DataFrame\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.
Copy link
Contributor

camdecoster commented Nov 17, 2025
edited
Loading

Thanks for the PR! We'll try to review this as we have time. This seems to be related to #4782.

Copy link
Member

@LiamConnors LiamConnors left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I have added a few comments. Let me know if you have any questions.

Comment on lines +84 to +85
import geodatasets
geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities'))
Copy link
Member

@LiamConnors LiamConnors Nov 20, 2025
edited
Loading

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

Comment on lines +60 to +74
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: 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",
)
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.

As 'naturalearth.cities' does not exist on geodatasets, I think the best thing to do here would be to have just the example of the dataframe created using GeoDataFrame, like you show in the except block, but with some real cities.

So something like

import plotly.express as px
import geopandas as gpd
from shapely.geometry import Point
geo_df = gpd.GeoDataFrame({
 'name': ['London', 'Paris', 'Berlin', 'Madrid', 'Rome'],
 'geometry': [
 Point(-0.13, 51.51),
 Point(2.35, 48.86),
 Point(13.41, 52.52),
 Point(-3.70, 40.42),
 Point(12.50, 41.90),
 ]
}, crs="EPSG:4326")
fig = px.scatter_map(geo_df,
 lat=geo_df.geometry.y,
 lon=geo_df.geometry.x,
 hover_name="name",
 zoom=3)
fig.show()

And something similar for the scatter-plots-on-maps example

Copy link
Contributor

emilykl commented Nov 24, 2025

@LiamConnors Any reason not to simply require geopandas>=1.0? I'm not sure if we need to provide examples for both old and new geopandas.

Copy link
Member

@LiamConnors Any reason not to simply require geopandas>=1.0? I'm not sure if we need to provide examples for both old and new geopandas.

I agree. It doesn't need to be compatible with old geopandas. Instead of having an example that creates theGeoDataFrame in the code, it would also be fine to just use one of the available datasets in geodatasets even if that won't work with earlier versions of geopandas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@LiamConnors LiamConnors LiamConnors left review comments

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Geopandas example for tile maps fails with geopandas>1.0

AltStyle によって変換されたページ (->オリジナル) /