You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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?
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.
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".
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
Activity
AlbertoFabbri93 commentedon Jul 24, 2026
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 becauseout=Nonewas omitted or misunderstood could silently destroy important intermediate results. Making overwriting an explicit opt-in would make the API safer.flying-sheep commentedon Jul 25, 2026
Interesting idea! The until now is “take X, write X, overwrite unless
copy=True”.How would you suggest this would look like?
AlbertoFabbri93 commentedon Jul 29, 2026
Maybe something like this:
What do you think?
selmanozleyen commentedon Jul 31, 2026
Maybe
out=Nonemeans return a copy (this would get rid ofcopy) andout=A.layers["counts"]would already mean overwrite no? because out="inplace" and copy=False would conflictAlbertoFabbri93 commentedon Aug 1, 2026
I like
in=A.layers["counts"]andout=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
countswith log transformed or scaled data very confusing... what is the usecase for supporting overwriting the input layer? Is it to save memory?use_repacceptanndata.accacessors #4314anndata.accbased API formask/mask_{obs,var}#4331anndata.accreplacement for functions takingobsm,layer, … #4334anndata.accbased API forobs_df,var_df#4360hanslovsky commentedon Oct 29, 2026
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
over
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 anin_Parameter, but skiplayer,obsm, andobspparameters? 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.hanslovsky commentedon Oct 30, 2026
I just saw #4359! Wonderful discussion in there and I think that answers my question in this thread. I think
useis a great choice for selecting input(s). It reads very naturally in the sense of "run pca and use this matrix for it".flying-sheep commentedon Nov 3, 2026
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"], ...}