Skip to content

basic support for AnnData accessors#147

Open
ilia-kats wants to merge 3 commits into
scverse:mainfrom
ilia-kats:accessor_support
Open

basic support for AnnData accessors#147
ilia-kats wants to merge 3 commits into
scverse:mainfrom
ilia-kats:accessor_support

Conversation

@ilia-kats

Copy link
Copy Markdown
Collaborator

The main point of this is to still be able to pass MuData objects to scanpy's plotting functions. This is currently possible due to MuData's implementation of obs_vector and var_vector, but if I understand the scanpy changes correctly (e.g. here) this will stop working as soon as anndata 0.13 is released.

The logic is based on the current _attr_vector implementation, which will go away at some point when obs_vector and var_vector are removed.

I'd appreciate some feedback on where else scanpy has switched to accessors. For example, it is currently possible to run sc.pp.neighbors and sc.tl.umap on a MuData object. Have these also switched to using accessors to access .obsm/obsp?

@ilia-kats ilia-kats requested review from gtca and ilan-gold May 7, 2026 09:20
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.48%. Comparing base (1837822) to head (ac1fbd2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
+ Coverage   91.38%   91.48%   +0.10%     
==========================================
  Files          10       10              
  Lines        1601     1620      +19     
==========================================
+ Hits         1463     1482      +19     
  Misses        138      138              
Files with missing lines Coverage Δ
src/mudata/_core/mudata.py 93.06% <100.00%> (+0.15%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ilia-kats added 3 commits June 8, 2026 14:26
this should keep scanpy plotting working with MuData objects

@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.

Let's wait for @flying-sheep to get back to review this. There may be a cleaner way to this aside from violating types


if isinstance(index, AdRef):
try:
return index.acc.get(self, index.idx)

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.

So this relies on the fact that MuData carries an obs, var etc. but does not follow the type?

https://anndata.readthedocs.io/en/latest/generated/anndata.acc.RefAcc.html#anndata.acc.RefAcc.get

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.

Maybe we should use a protocol?

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.

So this relies on the fact that MuData carries an obs, var etc. but does not follow the type?

Exactly.

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.

There may be a cleaner way to this aside from violating types.

You're violating types every time you pass a MuData to scanpy, everything there is typed as AnnData. Perhaps a protocol would indeed make sense.

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.

You're violating types every time you pass a MuData to scanpy, everything there is typed as AnnData. Perhaps a protocol would indeed make sense.

But maybe there's a way we can stop doing this now that scanpy is being redesigned - perhaps with a view to MuData.

@ilan-gold ilan-gold requested a review from flying-sheep June 8, 2026 12:54
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