Skip to content

Commit

Permalink
test(duckdb-geospatial): fix incomplete skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Jan 18, 2024
1 parent 08aca7e commit 1d06b87
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
4 changes: 3 additions & 1 deletion ibis/backends/base/sql/alchemy/geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from importlib.util import find_spec as _find_spec

geospatial_supported = (
_find_spec("geoalchemy2") is not None and _find_spec("geopandas") is not None
_find_spec("geoalchemy2") is not None
and _find_spec("geopandas") is not None
and _find_spec("shapely") is not None
)
__all__ = ["geospatial_supported"]
31 changes: 16 additions & 15 deletions ibis/backends/duckdb/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,34 @@ def con(data_dir, tmp_path_factory, worker_id):


@pytest.fixture(scope="session")
def zones(con, data_dir):
zones = con.read_geo(data_dir / "geojson" / "zones.geojson")
return zones
def gpd():
pytest.importorskip("shapely")
pytest.importorskip("geoalchemy2")
return pytest.importorskip("geopandas")


@pytest.fixture(scope="session")
def lines(con, data_dir):
lines = con.read_geo(data_dir / "geojson" / "lines.geojson")
return lines
def zones(con, data_dir, gpd):
return con.read_geo(data_dir / "geojson" / "zones.geojson")


@pytest.fixture(scope="session")
def zones_gdf(data_dir):
gpd = pytest.importorskip("geopandas")
zones_gdf = gpd.read_file(data_dir / "geojson" / "zones.geojson")
return zones_gdf
def lines(con, data_dir, gpd):
return con.read_geo(data_dir / "geojson" / "lines.geojson")


@pytest.fixture(scope="session")
def lines_gdf(data_dir):
gpd = pytest.importorskip("geopandas")
lines_gdf = gpd.read_file(data_dir / "geojson" / "lines.geojson")
return lines_gdf
def zones_gdf(data_dir, gpd):
return gpd.read_file(data_dir / "geojson" / "zones.geojson")


@pytest.fixture(scope="session")
def geotable(con):
def lines_gdf(data_dir, gpd):
return gpd.read_file(data_dir / "geojson" / "lines.geojson")


@pytest.fixture(scope="session")
def geotable(con, gpd):
return con.table("geo")


Expand Down
1 change: 1 addition & 0 deletions ibis/backends/duckdb/tests/test_geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
gpd = pytest.importorskip("geopandas")
gtm = pytest.importorskip("geopandas.testing")
shapely = pytest.importorskip("shapely")
pytest.importorskip("geoalchemy2")


def test_geospatial_point(zones, zones_gdf):
Expand Down
8 changes: 4 additions & 4 deletions ibis/backends/duckdb/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,24 @@ def test_load_spatial_when_geo_column(tmpdir):
assert "spatial" in con.sql(query).name.to_pandas().values


@pytest.mark.usefixtures("gpd")
def test_read_geo_to_pyarrow(con, data_dir):
pytest.importorskip("geopandas")
shapely = pytest.importorskip("shapely")

t = con.read_geo(data_dir / "geojson" / "zones.geojson")
raw_geometry = t.head().to_pyarrow()["geom"].to_pandas()
assert len(shapely.from_wkb(raw_geometry))


def test_read_geo_to_geopandas(con, data_dir):
gpd = pytest.importorskip("geopandas")
def test_read_geo_to_geopandas(con, data_dir, gpd):
t = con.read_geo(data_dir / "geojson" / "zones.geojson")
gdf = t.head().to_pandas()
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))
monkeypatch.setattr(con, "_load_extensions", lambda x, **_: 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
Expand Down Expand Up @@ -430,6 +429,7 @@ def test_csv_with_slash_n_null(con, tmp_path):
)
def test_register_filesystem_gcs(con):
fsspec = pytest.importorskip("fsspec")
pytest.importorskip("gcsfs")

gcs = fsspec.filesystem("gcs")

Expand Down

0 comments on commit 1d06b87

Please sign in to comment.