diff --git a/bento/geometry/_ops.py b/bento/geometry/_ops.py index bc600fa..c66da9a 100644 --- a/bento/geometry/_ops.py +++ b/bento/geometry/_ops.py @@ -49,7 +49,8 @@ def overlay( shape1 = sdata[s1] shape2 = sdata[s2] - new_shape = shape1.overlay(shape2, how=how, make_valid=make_valid) + new_shape = shape1.overlay(shape2, how=how, make_valid=make_valid)[["geometry"]] + new_shape.index = new_shape.index.astype(str) new_shape.attrs = {} transform = shape1.attrs diff --git a/bento/io/_index.py b/bento/io/_index.py index 903f8a8..c730dfd 100644 --- a/bento/io/_index.py +++ b/bento/io/_index.py @@ -124,6 +124,7 @@ def _sjoin_shapes( .dissolve(by="index_right", observed=True, dropna=False) .reset_index(drop=True)[["geometry"]] ) + child_shape.index = child_shape.index.astype(str) child_shape = ShapesModel.parse(child_shape) child_shape.attrs = child_attrs sdata.shapes[shape_key] = child_shape diff --git a/bento/io/_io.py b/bento/io/_io.py index 4ef7117..431df92 100644 --- a/bento/io/_io.py +++ b/bento/io/_io.py @@ -78,18 +78,10 @@ def prep( sdata.points[points_key].attrs["spatialdata_attrs"]["instance_key"] = instance_key pbar = tqdm(total=3) - if len(point_sjoin) > 0: - pbar.set_description("Mapping points") - sdata = _sjoin_points( - sdata=sdata, - points_key=points_key, - shape_keys=point_sjoin, - ) - - pbar.update() - if len(shape_sjoin) > 0: - pbar.set_description("Mapping shapes") + pbar.set_description( + "Mapping shapes" + ) # Map shapes must happen first; manyto1 mapping resets shape index sdata = _sjoin_shapes( sdata=sdata, instance_key=instance_key, @@ -99,6 +91,16 @@ def prep( pbar.update() + if len(point_sjoin) > 0: + pbar.set_description("Mapping points") + sdata = _sjoin_points( + sdata=sdata, + points_key=points_key, + shape_keys=point_sjoin, + ) + + pbar.update() + # Only keep points within instance_key shape _sync_points(sdata, points_key)