Refactor xenium reader#386
Merged
LucaMarconato merged 7 commits intomainfrom Apr 30, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #386 +/- ##
==========================================
+ Coverage 61.65% 62.15% +0.49%
==========================================
Files 27 27
Lines 3161 3181 +20
==========================================
+ Hits 1949 1977 +28
+ Misses 1212 1204 -8
🚀 New features to boost your workflow:
|
Rename _CellsZarr → _XeniumCells to reflect that it aggregates cell identity from multiple on-disk sources (zarr + parquet), not just zarr. Key changes: - nucleus_indices_mapping and cell_indices_mapping are now computed once in __post_init__ and stored on the instance; no caller recomputes them. - get_cell_metadata() added: reads cells.parquet, decodes cell_id to str, and cross-checks it against the zarr cell_id array. No other code reads the parquet cell_id independently. - get_cell_summary() returns None for v < 1.3.0 instead of asserting. - seg_mask_value branch in get_indices_mapping now validates the expected contiguous 1..N range and warns if violated. - _enrich_table() removed: cell_summary enrichment moved into _get_tables_and_circles(); cell_labels instance-key mapping moved into xenium() where it belongs conceptually. - _get_tables_and_circles() simplified (drops cells_labels and cells_as_circles parameters). - Docstrings updated to accurately document raster label semantics (label = p+1, not cell_index[p]+1), version differences, and the reasoning behind each branch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
_get_tables_and_circles always builds the circles object (needed for obsm["spatial"] and radii), but they should only appear in the output SpatialData when the user requests cells_as_circles=True. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Xenium reader (xenium.py) to centralize Xenium cell-ID/mapping logic and simplify the main xenium() control flow.
Changes:
- Introduces
_XeniumCellsdataclass to encapsulatecells.zarr.zipaccess, label-index mappings, and cell-summary/metadata helpers. - Refactors
xenium()to use the shared_XeniumCellscontext, streamlining table enrichment and boundary/label reading. - Extracts morphology-focus handling into
_get_morphology_focus()to separate version-specific image logic.
Comments suppressed due to low confidence (1)
src/spatialdata_io/readers/xenium.py:500
- The docstring says that when
indices_mappingisNone_get_polygons()"falls back to cell_id-based grouping". However, when the parquet containslabel_id(v2.0+), the grouping key becomeslabel_id(seecolumns_to_read.append("label_id" if has_label_id else cell_id)), so the fallback index will be derived from label IDs, not cell IDs. Please clarify the docstring (and/or forceindices_mappingto be provided whenlabel_idis present, since otherwise the resulting shapes cannot be keyed bycell_id).
indices_mapping
When provided (from ``_XeniumCells``),
contains ``cell_id`` and ``label_index`` columns. The parquet ``label_id`` column is used
for fast integer-based change detection (to locate all the vertices of each polygon).
When None, falls back to cell_id-based grouping from the parquet (Xenium < 2.0).
is_nucleus
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Member
Author
|
Claude Code (local) and Copilot review passed. Ready to merge. |
_decode_cell_id_column was unconditionally calling astype(str), converting plain-integer cell_ids (v1.0.x datasets) to strings. This broke merges against externally-generated CSVs that still hold int64 cell_ids. Restore the original behaviour: only decode bytes->str, leave other types unchanged. Also fix the cross-check assertion in _get_tables_and_circles to compare cell_ids as strings when the parquet column is numeric, matching what the old code did explicitly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code refactoring of the
xenium.pyto improve readability and maintainability.