From 8f012c42df7739f613fac2898a5b2d0d34316724 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 8 Nov 2023 14:41:26 -0500 Subject: [PATCH] fix(duckdb): gate geoalchemy import in duckdb geospatial --- ibis/backends/duckdb/registry.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ibis/backends/duckdb/registry.py b/ibis/backends/duckdb/registry.py index cd9b228acd74..649e718d4aa3 100644 --- a/ibis/backends/duckdb/registry.py +++ b/ibis/backends/duckdb/registry.py @@ -6,7 +6,6 @@ import numpy as np import sqlalchemy as sa -from geoalchemy2 import Geometry from sqlalchemy.ext.compiler import compiles from sqlalchemy.sql.functions import GenericFunction @@ -29,6 +28,18 @@ ) from ibis.common.exceptions import UnsupportedOperationError +try: + from geoalchemy2 import Geometry + + class Geometry_WKB(Geometry): + as_binary = "ST_AsWKB" + +except ImportError: + + class Geometry_WKB: + ... + + if TYPE_CHECKING: from collections.abc import Mapping @@ -56,10 +67,6 @@ def _round(t, op): } -class Geometry_WKB(Geometry): - as_binary = "ST_AsWKB" - - def _centroid(t, op): arg = t.translate(op.arg) return sa.func.st_centroid(arg, type_=Geometry_WKB)