-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnnData raw is a reference when a copy is expected #1139
Comments
I'm not sure I would consider this a bug. Assigning to other attributes of an AnnData doesn't cause a copy, and this would be a pretty large copy to make. You can instead do |
I guess it's mainly the (unintended?) behaviour change that is a bit of an issue for the users, e.g. as seen in the linked issue. Scanpy tutorials like the PBMC 3k one feature the code |
Would be easy to fix: @raw.setter
def _set_raw(self, raw: AnnData | Raw) -> None:
if self is raw:
raw = raw.copy()
... I don’t things |
I think this behavior is expected, and the old behavior was wrong. We generally try not to make too many defensive copies due to the large performance hit.
I don't think that happens? The behavior being described is that |
@ivirshup Nevertheless I think the issue for the user persists as Given this, I think this behaviour change should come with some note or a warning (not sure there was one?). Should we now open a cascade of issues to fix the tutorials? That's another topic but shouldn't we aim towards deprecating raw altogether? Just searching |
When X is a mutable DataFrame, that’s a problem (one of the reasons I didn’t want to allow data frames as .X)
I’d say yes |
Yes.
Maybe a comment in the tutorial would be appropriate? I don't think we should be recommending that people make big copies when it's not necessary. I think typically there is no unintended mutation here since people subset the anndata after assigning to raw, which makes I would like to replace the scanpy tutorial with the new tutorial, but the tutorial workflow got changed and needs fixing. |
@flying-sheep Can X be a dataframe? I'm pretty sure we aren't supporting that in |
Please make sure these conditions are met
Report
Code:
With anndata v0.8, for instance, the last line returns
False
.This causes issues like this one: scverse/muon#126.
Versions
Version info
The text was updated successfully, but these errors were encountered: