# Error with sc.pp.highly\_variable\_genes, pp.highly\_variable\_genes\` expects an \`AnnData\` argument

**URL:** <https://discourse.scverse.org/t/error-with-sc-pp-highly-variable-genes-pp-highly-variable-genes-expects-an-anndata-argument/767>\
**Category:** scanpy\
**Created:** [September 21, 2022, 4:47pm UTC](https://discourse.scverse.org/t/error-with-sc-pp-highly-variable-genes-pp-highly-variable-genes-expects-an-anndata-argument/767 "2022-09-21T16:47:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimelof](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/rimelof/32/380_2.png) [@rimelof](https://discourse.scverse.org/u/rimelof)\
**Post date:** [September 21, 2022, 4:47pm UTC](https://discourse.scverse.org/t/error-with-sc-pp-highly-variable-genes-pp-highly-variable-genes-expects-an-anndata-argument/767/1 "2022-09-21T16:47:02Z")

</div>

Hello,

I am following the scvi tutorial, and I am getting the following error:

> adata = sc.pp.highly\_variable\_genes(  
> adata,  
> flavor=“seurat\_v3”,  
> n\_top\_genes=2000,  
> batch\_key=“orig.ident”,  
> subset=True  
> )

> ValueError Traceback (most recent call last)  
> Input In [6], in \<cell line: 2\>()  
> 1 adata.raw = adata # keep full dimension safe  
> ----\> 2 var = sc.pp.highly\_variable\_genes(  
> 3 adata,  
> 4 flavor=“seurat\_v3”,  
> 5 n\_top\_genes=2000,  
> 6 batch\_key=“orig.ident”,  
> 7 subset=True,  
> 8 inplace=False  
> 9 )
> 
> File ~/.local/lib/python3.9/site-packages/scanpy/preprocessing/\_highly\_variable\_genes.py:422, in highly\_variable\_genes(adata, layer, n\_top\_genes, min\_disp, max\_disp, min\_mean, max\_mean, span, n\_bins, flavor, subset, inplace, batch\_key, check\_values)  
> 416 raise ValueError(  
> 417 '`pp.highly_variable_genes` expects an `AnnData` argument, ’  
> 418 ‘pass `inplace=False` if you want to return a `pd.DataFrame`.’  
> 419 )  
> 421 if flavor == ‘seurat\_v3’:  
> → 422 return \_highly\_variable\_genes\_seurat\_v3(  
> 423 adata,  
> 424 layer=layer,  
> 425 n\_top\_genes=n\_top\_genes,  
> 426 batch\_key=batch\_key,  
> 427 check\_values=check\_values,  
> 428 span=span,  
> 429 subset=subset,  
> 430 inplace=inplace,  
> 431 )  
> 433 if batch\_key is None:  
> 434 df = \_highly\_variable\_genes\_single\_batch(  
> 435 adata,  
> 436 layer=layer,  
> (…)  
> 443 flavor=flavor,  
> 444 )
> 
> File ~/.local/lib/python3.9/site-packages/scanpy/preprocessing/\_highly\_variable\_genes.py:85, in \_highly\_variable\_genes\_seurat\_v3(adata, layer, n\_top\_genes, batch\_key, check\_values, span, subset, inplace)  
> 83 x = np.log10(mean[not\_const])  
> 84 model = loess(x, y, span=span, degree=2)  
> —\> 85 model.fit()  
> 86 estimat\_var[not\_const] = model.outputs.fitted\_values  
> 87 reg\_std = np.sqrt(10\*\*estimat\_var)
> 
> File \_loess.pyx:899, in \_loess.loess.fit()
> 
> ValueError: b’reciprocal condition number 5.0015e-16\n’

Digging around I found suggestions this might be due to several genes with 0 counts, which I expect, so I tried filtering. But

> adata=sc.pp.filter\_genes(adata, min\_cells=1)

results in

> * * *
> 
> TypeError Traceback (most recent call last)  
> Input In [4], in \<cell line: 3\>()  
> 1 adata.raw = adata # keep full dimension safe  
> 2 adata=sc.pp.filter\_cells(adata, min\_genes=200)  
> ----\> 3 adata=sc.pp.filter\_genes(adata, min\_cells=1)  
> 4 var = sc.pp.highly\_variable\_genes(  
> 5 adata,  
> 6 flavor=“seurat\_v3”,  
> (…)  
> 10 inplace=False  
> 11 )
> 
> File ~/.local/lib/python3.9/site-packages/scanpy/preprocessing/\_simple.py:259, in filter\_genes(data, min\_counts, min\_cells, max\_counts, max\_cells, inplace, copy)  
> 256 min\_number = min\_counts if min\_cells is None else min\_cells  
> 257 max\_number = max\_counts if max\_cells is None else max\_cells  
> 258 number\_per\_gene = np.sum(  
> → 259 X if min\_cells is None and max\_cells is None else X \> 0, axis=0  
> 260 )  
> 261 if issparse(X):  
> 262 number\_per\_gene = number\_per\_gene.A1
> 
> TypeError: ‘\>’ not supported between instances of ‘NoneType’ and ‘int’  
> TypeError: ‘\>’ not supported between instances of ‘NoneType’ and ‘int’

Not sure what could be causing it. I would like to avoid re-filtering, since I am combining preprocessed data.

Thanks!
