A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: detect CRS-qualified DuckDB geometry (#10643)
Kiran Gadhave90a8d1f84bdb
diff --git a/marimo/_data/get_datasets.py b/marimo/_data/get_datasets.pyindex 7b673fdbd6..0edac7e44c 100644--- a/marimo/_data/get_datasets.py+++ b/marimo/_data/get_datasets.py@@ -571,8 +571,9 @@ def _db_type_to_data_type(db_type: str) -> DataType:if db_type == "enum" or db_type.startswith("enum"):return "string"- # Spatial extension types- if db_type in _GEOMETRY_TYPES:+ # GEOMETRY has been core in DuckDB since version 1.5; it is not a spatial+ # extension type.+ if db_type in _GEOMETRY_TYPES or db_type.startswith("geometry("):return "geometry"# Nested typesdiff --git a/marimo/_plugins/ui/_impl/tables/geometry.py b/marimo/_plugins/ui/_impl/tables/geometry.pyindex 0fb889e37e..b3ac2689c5 100644--- a/marimo/_plugins/ui/_impl/tables/geometry.py+++ b/marimo/_plugins/ui/_impl/tables/geometry.py@@ -114,7 +114,7 @@ def _duckdb_geometry_columns(infos: dict[str, GeometryColumnInfo] = {}for name, dtype in zip(native.columns, native.types, strict=False):type_name = str(dtype)- if type_name == _DUCKDB_WKB_TYPE:+ if type_name == _DUCKDB_WKB_TYPE or type_name.startswith("GEOMETRY("):infos[name] = GeometryColumnInfo(encoding="wkb", external_type=type_name)diff --git a/tests/_data/test_get_datasets.py b/tests/_data/test_get_datasets.pyindex 14abf97771..f31156413e 100644--- a/tests/_data/test_get_datasets.py+++ b/tests/_data/test_get_datasets.py@@ -683,6 +683,8 @@ def test_db_type_to_data_type_various() -> None:# Special typesassert _db_type_to_data_type("geometry") == "geometry"+ assert _db_type_to_data_type("geometry('ogc:crs84')") == "geometry"+ assert _db_type_to_data_type("geometry('epsg:7415')") == "geometry"assert _db_type_to_data_type("point_2d") == "geometry"assert _db_type_to_data_type("linestring_2d") == "geometry"assert _db_type_to_data_type("polygon_2d") == "geometry"diff --git a/tests/_plugins/ui/_impl/tables/geometry_fixtures.py b/tests/_plugins/ui/_impl/tables/geometry_fixtures.pyindex b01f2d4313..e2c9f9ba43 100644--- a/tests/_plugins/ui/_impl/tables/geometry_fixtures.py+++ b/tests/_plugins/ui/_impl/tables/geometry_fixtures.py@@ -246,6 +246,19 @@ def duckdb_geometry_relation()+def duckdb_crs_geometry_connection() -> duckdb_mod.DuckDBPyConnection:+ """In-memory connection with a CRS-parameterized geometry table, or skip."""+ import duckdb++ conn = duckdb.connect()+ try:+ conn.execute("CREATE TABLE crs_geometry (geom GEOMETRY('OGC:CRS84'))")+ except duckdb.Error as e:+ conn.close()+ pytest.skip(f"duckdb CRS-parameterized geometry unavailable: {e}")+ return conn++# --- ibis --------------------------------------------------------------diff --git a/tests/_plugins/ui/_impl/tables/test_geometry.py b/tests/_plugins/ui/_impl/tables/test_geometry.pyindex a9a619f146..f95a475b88 100644--- a/tests/_plugins/ui/_impl/tables/test_geometry.py+++ b/tests/_plugins/ui/_impl/tables/test_geometry.py@@ -157,6 +157,19 @@ class TestArrowDetection:@pytest.mark.requires("duckdb")class TestDuckDBDetection:+ def test_detects_crs_parameterized_geometry_column(self) -> None:+ conn = geo.duckdb_crs_geometry_connection()+ try:+ manager = get_table_manager(conn.table("crs_geometry"))++ assert manager.get_field_type("geom") == (+ "geometry",+ "GEOMETRY('OGC:CRS84')",+ )+ assert manager._geometry_columns["geom"].encoding == "wkb"+ finally:+ conn.close()+def test_detects_geometry_relation_columns(self) -> None:import narwhals.stable.v2 as nw