# Cannot modify AnnData object

**URL:** <https://discourse.scverse.org/t/cannot-modify-anndata-object/2073>\
**Category:** anndata\
**Created:** [February 9, 2024, 5:20pm UTC](https://discourse.scverse.org/t/cannot-modify-anndata-object/2073 "2024-02-09T17:20:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mduvina](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/mduvina/32/957_2.png) [@mduvina](https://discourse.scverse.org/u/mduvina)\
**Post date:** [February 9, 2024, 5:20pm UTC](https://discourse.scverse.org/t/cannot-modify-anndata-object/2073/1 "2024-02-09T17:20:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ivirshup](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/ivirshup/32/160_2.png) [@ivirshup](https://discourse.scverse.org/u/ivirshup)\
**Post date:** [February 13, 2024, 10:22am UTC](https://discourse.scverse.org/t/cannot-modify-anndata-object/2073/2 "2024-02-13T10:22:50Z")

</div>

I believe the issue is the version of pandas. Right not anndata actually it’s [not compatible with `pandas==2.1.2`](https://github.com/scverse/anndata/blob/96d82eb30a79638c794a844fa236d5b259632466/pyproject.toml#L42), which should have meant pip would complain about it.

If updating your version of pandas doesn’t help, please open an issue on the anndata issue tracker: [Issues · scverse/anndata · GitHub](https://github.com/scverse/anndata/issues)

---

<div class="post-metadata">

**Author:** ![mduvina](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/mduvina/32/957_2.png) [@mduvina](https://discourse.scverse.org/u/mduvina)\
**Post date:** [February 16, 2024, 3:42pm UTC](https://discourse.scverse.org/t/cannot-modify-anndata-object/2073/3 "2024-02-16T15:42:02Z")

</div>

Indeed, that’s what it was. Upgrading to pandas 2.2 solved the problem - thank for your help.
