Skip to content

Commit 3baf509

Browse files
ncclementigforsyth
authored andcommitted
feat(geospatial): update read_geo to support url
In the upcoming update of the spatial extension, to be able to read form a url, the httpfs extension is needed.
1 parent 72752eb commit 3baf509

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ibis/backends/duckdb/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,13 @@ def read_geo(
528528
# load geospatial extension
529529
self.load_extension("spatial")
530530

531+
source = util.normalize_filename(source)
532+
533+
if source.startswith(("http://", "https://", "s3://")):
534+
self._load_extensions(["httpfs"])
535+
531536
source_expr = sa.select(sa.literal_column("*")).select_from(
532-
sa.func.st_read(util.normalize_filename(source), _format_kwargs(kwargs))
537+
sa.func.st_read(source, _format_kwargs(kwargs))
533538
)
534539

535540
view = self._compile_temp_view(table_name, source_expr)

ibis/backends/duckdb/tests/test_register.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ def test_read_geo_to_geopandas(con, data_dir):
108108
assert isinstance(gdf, gpd.GeoDataFrame)
109109

110110

111+
def test_read_geo_from_url(con, monkeypatch):
112+
loaded_exts = []
113+
monkeypatch.setattr(con, "_load_extensions", lambda x, **kw: loaded_exts.extend(x))
114+
115+
with pytest.raises((sa.exc.OperationalError, sa.exc.ProgrammingError)):
116+
# The read will fail, either because the URL is bogus (which it is) or
117+
# because the current connection doesn't have the spatial extension
118+
# installed and so the call to `st_read` will raise a catalog error.
119+
con.read_geo("https://...")
120+
121+
assert "spatial" in loaded_exts
122+
assert "httpfs" in loaded_exts
123+
124+
111125
@pytest.mark.xfail_version(
112126
duckdb=["duckdb<0.7.0"], reason="read_json_auto doesn't exist", raises=exc.IbisError
113127
)

0 commit comments

Comments
 (0)