From 0af5074a9a79c7560a669c21e4bbb363c7720b30 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Tue, 27 Aug 2024 19:21:38 +0200 Subject: [PATCH] BUG: catch empty GeometryIndex in repr --- xvec/index.py | 2 ++ xvec/tests/test_index.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/xvec/index.py b/xvec/index.py index a05b632..ea71cfb 100644 --- a/xvec/index.py +++ b/xvec/index.py @@ -277,6 +277,8 @@ def _repr_inline_(self, max_width: int) -> str: def __repr__(self) -> str: srs = _format_crs(self.crs) shape = self._index.index.shape[0] + if shape == 0: + return f"GeometryIndex([], crs={srs})" if shape < 10: wkts = [repr(g) for g in self._index.index] else: diff --git a/xvec/tests/test_index.py b/xvec/tests/test_index.py index a4d0cd1..6a7cfbe 100644 --- a/xvec/tests/test_index.py +++ b/xvec/tests/test_index.py @@ -193,3 +193,8 @@ def test_repr(geom_dataset, geom_dataset_no_crs): long = xr.concat([geom_dataset] * 10, dim="geom") actual = repr(long.xindexes["geom"]) expected = "GeometryIndex(\n [\n \n \n \n ...\n \n \n \n ],\n crs=EPSG:26915)" + + empty = geom_dataset.xvec.query("geom", shapely.Point(0, 0), predicate="intersects") + actual = repr(empty.xindexes["geom"]) + expected = "GeometryIndex([], crs=EPSG:26915)" + assert actual == expected