Skip to content

Full accessor support#158

Open
ilia-kats wants to merge 19 commits into
scverse:mainfrom
ilia-kats:accessors
Open

Full accessor support#158
ilia-kats wants to merge 19 commits into
scverse:mainfrom
ilia-kats:accessors

Conversation

@ilia-kats

@ilia-kats ilia-kats commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Implement MuData acessors. These are similar to and build on AnnData accessors, but add an additional level for modalities. So it is now possible to e.g. do

from mudata.acc import A

acc = A.mod["rna"].obs["cell_type"]

mdata[acc]

@ilia-kats ilia-kats requested review from gtca and ilan-gold June 8, 2026 12:45
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.56219% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.09%. Comparing base (2d32c11) to head (fae2153).

Files with missing lines Patch % Lines
src/mudata/acc/__init__.py 87.30% 24 Missing ⚠️
src/mudata/_core/mudata.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #158      +/-   ##
==========================================
- Coverage   91.53%   91.09%   -0.45%     
==========================================
  Files          10       11       +1     
  Lines        1619     1819     +200     
==========================================
+ Hits         1482     1657     +175     
- Misses        137      162      +25     
Files with missing lines Coverage Δ
src/mudata/__init__.py 100.00% <100.00%> (ø)
src/mudata/_core/mudata.py 93.11% <87.50%> (-0.06%) ⬇️
src/mudata/acc/__init__.py 87.30% <87.30%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ilia-kats ilia-kats requested review from ilan-gold and removed request for ilan-gold June 17, 2026 14:53

@ilan-gold ilan-gold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice pretty clean!

Comment thread src/mudata/__init__.py
Comment thread tests/test_accessors.py
del MuAcc.__dataclass_fields__["layers"]
del MuAcc.__dataclass_fields__["layer_cls"]

A: MuAcc[AdRef] = MuAcc()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A: MuAcc[AdRef] = MuAcc()
M: MuAcc[AdRef] = MuAcc()

or?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed A stands for accessor, not AnnData. But I'm fine with calling this M.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had genuinely never thought of that but it makes sense. I thought of it as accessor for AnnData. @flying-sheep thoughts here?

Comment on lines +278 to +287
def to_json(self, ref: R) -> list[str | int | None]:
"""Serialize :class:`~anndata.acc.AdRef` to a JSON-compatible list."""
if isinstance(ref.acc, ModMapAcc):
return [f"{ref.acc.dim}map", ref.idx]

ret = super().to_json(ref)
if isinstance(ref.acc, _ModalityMixin):
ret = ["mod", ref.acc.mod, ret]
return ret

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a JSON-schema for this - it may be worth doing this for MuData (in a way that builds on ours maybe?): https://anndata.scverse.org/en/latest/generated/anndata.acc.AdAcc.html#anndata.acc.AdAcc.from_json

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a schema.

Comment on lines +300 to +303
del MuAcc.__dataclass_fields__["X"]
del MuAcc.__dataclass_fields__["layers"]
del MuAcc.__dataclass_fields__["layer_cls"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a better way to support this, maybe @flying-sheep has an idea. Bu this seems fine to me at first glance

ilia-kats and others added 3 commits June 24, 2026 09:19
Co-authored-by: Ilan Gold <ilanbassgold@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants