Fix repeated slicing causing missing uns
, AttributeError
#133
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #77
Minimal repro of
AttributeError
(before this fix)Stack trace
Reasons for the AttributeError
Three things combined to cause a slice of a slice of a slice to crash:
Views can't be
deepcopy
'd:__setitem__
calls_init_actual_AnnData
callsisbacked
→filename
→file
file
isn't set whiledeepcopy
is iterating through KVs calling__setitem__
.I considered just checking whether
file
was set yet when accessingfilename
, but this is not a very robust solution. This deepcopy problem was causing other issues (for example,uns
on a slice of a slice was erroneously empty), and was liable to affect lots of fields._uns
getsdeepcopy
'd when making a viewcode:
On views,
_uns
holds a reference to its enclosing AnnDatacode:
Fix
I resolved this problem by overriding
_ViewMixin.__deepcopy__
to make adeepcopy
of [the view's parent AnnData]'s copy of the field in question.I think this should make things strictly more robust (as opposed to this being a hack to just make things work), but if it may break other assumptions lmk.