scverse / scverse/scanpy

ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual. self.data[key] = value

Open
#2,428 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the master branch of scanpy.
#remove all ribosomal genes
malat1 = adata1.var_names.str.startswith('MALAT1')
ribo_genes = adata1.var_names.str.startswith(("RPS","RPL"))
# we need to redefine the mito_genes since they were first 
# calculated on the full object before removing low expressed genes.
mito_genes = adata1.var_names.str.startswith('MT-')
hb_genes = adata1.var_names.str.contains('^HB[^(P)]')

remove = np.add(mito_genes, malat1)
remove = np.add(remove, hb_genes)
keep = np.invert(remove)

adata3 = adata1[:,keep]

adata3
Versions

anndata 0.8.0
scanpy 1.7.2

I am getting this error "ImplicitModificationWarning: Trying to modify attribute ._uns of view, initializing view as actual.
self.data[key] = value " as soon as i write the above code(subset data based on genes i need) and then the kernel crashes because of memory issues

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported gene-subsetting snippet with the listed Scanpy and anndata versions, then trace the view initialization and memory behavior in the relevant code paths. Done means the operation no longer produces the reported warning followed by a kernel crash, with the behavior verified against an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
bioinformatics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.