Skip to content

Commit

Permalink
feat(geospatial): update read_geo to support url
Browse files Browse the repository at this point in the history
In the upcoming update of the spatial extension, to be able to
read form a url, the httpfs extension is needed.
  • Loading branch information
ncclementi authored and gforsyth committed Dec 18, 2023
1 parent 72752eb commit 3baf509
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,13 @@ def read_geo(
# load geospatial extension
self.load_extension("spatial")

source = util.normalize_filename(source)

if source.startswith(("http://", "https://", "s3://")):
self._load_extensions(["httpfs"])

source_expr = sa.select(sa.literal_column("*")).select_from(
sa.func.st_read(util.normalize_filename(source), _format_kwargs(kwargs))
sa.func.st_read(source, _format_kwargs(kwargs))
)

view = self._compile_temp_view(table_name, source_expr)
Expand Down
14 changes: 14 additions & 0 deletions ibis/backends/duckdb/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ def test_read_geo_to_geopandas(con, data_dir):
assert isinstance(gdf, gpd.GeoDataFrame)


def test_read_geo_from_url(con, monkeypatch):
loaded_exts = []
monkeypatch.setattr(con, "_load_extensions", lambda x, **kw: loaded_exts.extend(x))

with pytest.raises((sa.exc.OperationalError, sa.exc.ProgrammingError)):
# The read will fail, either because the URL is bogus (which it is) or
# because the current connection doesn't have the spatial extension
# installed and so the call to `st_read` will raise a catalog error.
con.read_geo("https://...")

assert "spatial" in loaded_exts
assert "httpfs" in loaded_exts


@pytest.mark.xfail_version(
duckdb=["duckdb<0.7.0"], reason="read_json_auto doesn't exist", raises=exc.IbisError
)
Expand Down

0 comments on commit 3baf509

Please sign in to comment.