Skip to content

Commit

Permalink
BUG: catch empty GeometryIndex in repr (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis authored Aug 27, 2024
1 parent ba7ef28 commit 66b541b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xvec/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions xvec/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<POINT (1 2)>\n <POINT (3 4)>\n <POINT (1 2)>\n <POINT (3 4)>\n ...\n <POINT (1 2)>\n <POINT (3 4)>\n <POINT (1 2)>\n <POINT (3 4)>],\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

0 comments on commit 66b541b

Please sign in to comment.