Skip to content

Commit c144815

Browse files
committed
fix compatibility issue with older xenium versions (label_id missing)
1 parent 6b90042 commit c144815

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/spatialdata_io/readers/xenium.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,13 @@ def _get_polygons(
468468
labels, correctly handling multinucleate cells.
469469
When False (cell boundaries), use ``cell_id`` as the GeoDataFrame index.
470470
"""
471+
# Check whether the parquet has a label_id column (v2.0+). When present, use it for
472+
# fast integer-based change detection. Otherwise fall back to cell_id strings.
473+
parquet_schema = pq.read_schema(path / file)
474+
has_label_id = "label_id" in parquet_schema.names
475+
471476
columns_to_read = [str(XeniumKeys.BOUNDARIES_VERTEX_X), str(XeniumKeys.BOUNDARIES_VERTEX_Y)]
472-
if indices_mapping is not None:
473-
columns_to_read.append("label_id")
474-
else:
475-
columns_to_read.append(str(XeniumKeys.CELL_ID))
477+
columns_to_read.append("label_id" if has_label_id else str(XeniumKeys.CELL_ID))
476478
table = pq.read_table(path / file, columns=columns_to_read)
477479

478480
x = table.column(str(XeniumKeys.BOUNDARIES_VERTEX_X)).to_numpy()
@@ -481,7 +483,7 @@ def _get_polygons(
481483

482484
n = len(x)
483485

484-
if indices_mapping is not None:
486+
if has_label_id:
485487
id_col = table.column("label_id")
486488
id_arr = id_col.to_numpy()
487489
change_mask = id_arr[1:] != id_arr[:-1]

0 commit comments

Comments
 (0)