Hi,
I have a strange problem with the AnnData object. I can’t seem to modify any of the fields.
adata = sc.read_10x_h5(file)
adata.var_names_make_unique()
AnnData object with n_obs × n_vars = 6185 × 32285
var: ‘gene_ids’, ‘feature_types’, ‘genome’
when I run :
sc.pp.filter_cells(adata, min_counts=2000, inplace=False)
filtered out 1228 cells that have less than 2000 counts
it’s fine (don’t modify the object) but when I run :
sc.pp.filter_cells(adata, min_counts=2000, inplace=True) # → modify the object
I have :
/usr/local/lib/python3.11/dist-packages/anndata/_core/views.py:79: ImplicitModificationWarning: Trying to modify attribute
.var
of view, initializing view as actual.
container[idx] = value
/usr/local/lib/python3.11/dist-packages/anndata/_core/anndata.py:1908: UserWarning: Variable names are not unique. To make them unique, call.var_names_make_unique
.
utils.warn_names_duplicates(“var”)
/usr/local/lib/python3.11/dist-packages/anndata/_core/views.py:79: ImplicitModificationWarning: Trying to modify attribute.var
of view, initializing view as actual.
container[idx] = value
/usr/local/lib/python3.11/dist-packages/anndata/_core/anndata.py:1908: UserWarning: Variable names are not unique. To make them unique, call.var_names_make_unique
.
utils.warn_names_duplicates(“var”)
/usr/local/lib/python3.11/dist-packages/anndata/_core/views.py:79: ImplicitModificationWarning: Trying to modify attribute.var
of view, initializing view as actual.
container[idx] = value
ad infinitum, or more exactly until a maximum recursion depth exceeded error is raised.
In fact I can’t modify any of the .obs or .var fields, even this gives me the same error (adding a ‘test’ field):
adata.var[‘test’] = adata.var[‘gene_ids’]
Thanks for your help !
(packages version):
scanpy==1.9.8 anndata==0.10.5.post1 umap==0.5.4 numpy==1.26.1 scipy==1.11.3 pandas==2.1.2 scikit-learn==1.3.2 statsmodels==0.14.1 pynndescent==0.5.10