Skip to content

anndata.acc based API #4007

Open
3 of 4 issues completed
Open

Description

@flying-sheep

What kind of feature would you like to request?

Additional function parameters / changed functionality / changed defaults?

Please describe your wishes

instead of layer or obsm, we should have in_/out or so, where out=None means override.

I had Claude search for all spots that are still missing: link

Sub-issues

Sub-issues

3 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    Triage 🩺
    on Mar 23, 2026
  2. added
    Area – API
    and removed
    Triage 🩺
    on Mar 23, 2026
  3. AlbertoFabbri93 commented on Jul 24, 2026

    @AlbertoFabbri93
    Contributor

    I think overwriting should require an explicit decision. Layers in AnnData usually have semantic meanings (e.g. counts, log1p, scaled_counts) and often represent different stages of an analysis. Accidentally overwriting one because out=None was omitted or misunderstood could silently destroy important intermediate results. Making overwriting an explicit opt-in would make the API safer.

  4. flying-sheep commented on Jul 25, 2026

    @flying-sheep
    MemberAuthor

    Interesting idea! The until now is “take X, write X, overwrite unless copy=True”.

    How would you suggest this would look like?

  5. AlbertoFabbri93 commented on Jul 29, 2026

    @AlbertoFabbri93
    Contributor

    Maybe something like this:

    sc.pp.scale(
        adata,
        in=A.layers["counts"],
        out=A.layers["scaled_counts"],  # write to a new layer
    )
    
    sc.pp.scale(
        adata,
        in=A.layers["counts"],
        out="inplace",                  # explicit overwrite
    )

    What do you think?

  6. self-assigned this
    on Jul 30, 2026
  7. selmanozleyen commented on Jul 31, 2026

    @selmanozleyen
    Member

    Maybe out=None means return a copy (this would get rid of copy) and out=A.layers["counts"] would already mean overwrite no? because out="inplace" and copy=False would conflict

  8. AlbertoFabbri93 commented on Aug 1, 2026

    @AlbertoFabbri93
    Contributor

    I like in=A.layers["counts"] and out=A.layers["counts"] when the goal is to overwrite the layer because it is very explicit and obvious but some people might find it too "verbose".

    Btw I find overwriting a layer called counts with log transformed or scaled data very confusing... what is the usecase for supporting overwriting the input layer? Is it to save memory?

  9. hanslovsky commented on Oct 29, 2026

    @hanslovsky

    I agree that overwrite should only happen when it is explicitly asked for. I usually don't even want to have my object modified that I pass into a function, i.e. I consider inputs immutable. Even from a convenience POV, I would prefer

    data.layers[key] = func(data).X
    

    over

    func(data, out="layers.key")
    

    I really like the change to support accessor based selection over layer= etc. Is the idea that this will become a standard in the scverse world? I.e. if I want to write a new function, would it be appropriate to only support an in_ Parameter, but skip layer, obsm, and obsp parameters? I don't have any legacy code that holds those parameters, so far I always expected the data in X and let the user handle creating an appropriate an data object. I have had requests to add that convenience into my functions and a single in_ parameter would make things a lot easier.

  10. hanslovsky commented on Oct 30, 2026

    @hanslovsky

    I just saw #4359! Wonderful discussion in there and I think that answers my question in this thread. I think use is a great choice for selecting input(s). It reads very naturally in the sense of "run pca and use this matrix for it".

  11. flying-sheep commented on Nov 3, 2026

    @flying-sheep
    MemberAuthor

    Thank you! it’s very much supposed to become a standard.

    Building that PR I found a bunch of stuff we still need, but I think the design is good now. “derive key for secondary outputs from primary” makes sense I think.

    @ilan-gold suggested a registry of how to do this, which we should still do. Something like

    >>> sc.get.out.pp.neighbors(A.obsp["n"])
    {"connectivities": A.obsp["n"], "distances": A.obsp["n_distances"], ...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area – API

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions