Skip to content

Commit

Permalink
fix(duckdb): load extension when executing geospatial expressions (#9080
Browse files Browse the repository at this point in the history
)

- Closes #9076
  • Loading branch information
ncclementi authored Apr 30, 2024
1 parent f926995 commit 1960d54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def _to_sqlglot(

if not geocols:
return sql
else:
self._load_extensions(["spatial"])

return sg.select(
*(
Expand Down
15 changes: 13 additions & 2 deletions ibis/backends/duckdb/tests/test_geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_load_geo_example(con):


# For the next two tests we really want to ensure that
# load_extenstion("spatial") hasn't been run yet, so we create a new connection
# load_extension("spatial") hasn't been run yet, so we create a new connection
# instead of using the con fixture.


Expand All @@ -319,7 +319,7 @@ def geo_line_lit():
return ibis.literal(shapely.LineString([[0, 0], [1, 0], [1, 1]]), type="geometry")


@pytest.fixture(scope="session")
@pytest.fixture
def ext_dir(tmp_path_factory):
# this directory is necessary because of Windows extension downloads race
# condition
Expand Down Expand Up @@ -347,3 +347,14 @@ def test_cast_wkb_to_geo(con):
geo_expr = t.geometry.cast("geometry")
assert geo_expr.type().is_geospatial()
assert isinstance(con.execute(geo_expr), gpd.GeoSeries)


def test_load_spatial_casting(ext_dir):
con = ibis.duckdb.connect(extension_directory=ext_dir)
parquet_file = "https://github.com/ibis-project/testing-data/raw/master/parquet/geo_wkb.parquet"
t = con.read_parquet(parquet_file)

geo_expr = t.geometry.cast("geometry")

assert geo_expr.type().is_geospatial()
assert isinstance(con.execute(geo_expr), gpd.GeoSeries)

0 comments on commit 1960d54

Please sign in to comment.