Skip to content

Support Geopandas 1 #148

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

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions examples/Overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,10 @@
],
"source": [
"import geopandas\n",
"from download import download_map\n",
"\n",
"world_gp = geopandas.read_file(\n",
" geopandas.datasets.get_path('naturalearth_lowres')\n",
" download_map('naturalearth_lowres')\n",
")\n",
"world_gp = world_gp.sort_values('name').reset_index(drop=True)\n",
"world_gp = world_gp[['pop_est', 'continent', 'name', 'geometry']]\n",
Expand Down Expand Up @@ -3123,7 +3124,7 @@
],
"source": [
"cities_gp = geopandas.read_file(\n",
" geopandas.datasets.get_path('naturalearth_cities')\n",
" download_map('naturalearth_cities')\n",
")\n",
"cities_df = GeoDataFrame(cities_gp)\n",
"cities_df.head()"
Expand Down
34 changes: 34 additions & 0 deletions examples/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
try:
import requests
from platformdirs import user_cache_path
except ImportError:
raise ImportError("requests and platformdirs are needed to download data")


def download_map(dataset):
if dataset not in ("naturalearth_lowres", "naturalearth_cities"):
raise ValueError(f"Unknown dataset: {dataset}, supported datasets are 'naturalearth_lowres' and 'naturalearth_cities'")
url = f"https://api.github.com/repos/geopandas/geopandas/contents/geopandas/datasets/{dataset}?ref=v0.14.4"
local_dir = user_cache_path() / "spatialpandas" / dataset

if local_dir.exists():
return local_dir

response = requests.get(url)
if response.status_code == 200:
files = response.json()
else:
print(f"Failed to retrieve contents: {response.status_code}")
return None

if not local_dir.exists():
local_dir.mkdir(parents=True)

for file in files:
file_url = file["download_url"]
file_name = file["name"]
file_response = requests.get(file_url)
with open(local_dir / file_name, "wb") as f:
f.write(file_response.content)

return local_dir
6 changes: 4 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ python = "3.12.*"
datashader = "*"
descartes = "*"
distributed = "*"
geopandas-base = "<1" # FIX: temporary upper pin
pyogrio = "*"
geopandas-base = "*"
holoviews = "*"
matplotlib-base = "*"
platformdirs = "*"
pyogrio = "*"
requests = "*"

# =============================================
# =================== TESTS ===================
Expand Down
2 changes: 2 additions & 0 deletions spatialpandas/tests/tools/test_sjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def test_sjoin(how, gp_points, gp_polygons):
gp_expected = gp_expected.rename(columns={"v_x": "v_left", "v_y": "v_right"})
if how == "right":
gp_expected.index.name = right_gpdf.index.name
gp_expected = gp_expected.rename(columns={"a_left": "index_left", "a_right": "a"}) # geopandas 1.0 compability
else:
gp_expected.index.name = left_gpdf.index.name
gp_expected = gp_expected.rename(columns={"b": "index_right", "a_right": "a"}) # geopandas 1.0 compability

# join with spatialpandas
left_spdf = GeoDataFrame(left_gpdf)
Expand Down