# IndexError: list index out of range when running \`sc.pp.neighbors(adata)\`

**URL:** <https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432>\
**Category:** Help\
**Created:** [August 6, 2024, 12:08pm UTC](https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432 "2024-08-06T12:08:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YonSa](https://avatars.discourse-cdn.com/v4/letter/y/53a042/32.png) [@YonSa](https://discourse.scverse.org/u/YonSa)\
**Post date:** [August 6, 2024, 12:08pm UTC](https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432/1 "2024-08-06T12:08:53Z")

</div>

Hi,  
I’m getting the following stack trace when calling `sc.pp.neighbors(adata)`. This is data derived from CosMx, through squidpy, and as far as I know it’s valid - I’ve been analysing it for a while now.  
Python version is 3.12.4.  
Would appreciate any ideas, thanks!

It’s quite a long trace…  
[https://paste.mozilla.org/aWzoUOFC](https://paste.mozilla.org/aWzoUOFC)

---

<div class="post-metadata">

**Author:** ![Zethson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/zethson/32/152_2.png) [@Zethson](https://discourse.scverse.org/u/Zethson)\
**Post date:** [August 6, 2024, 12:17pm UTC](https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432/2 "2024-08-06T12:17:59Z")

</div>

Could you please give us the output of `pip list`? Especially the numba versions etc are of interest.

---

<div class="post-metadata">

**Author:** ![YonSa](https://avatars.discourse-cdn.com/v4/letter/y/53a042/32.png) [@YonSa](https://discourse.scverse.org/u/YonSa)\
**Post date:** [August 6, 2024, 12:57pm UTC](https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432/3 "2024-08-06T12:57:34Z")

</div>

Sure, this is the output of `conda list`:  
[https://paste.mozilla.org/4QssuEur](https://paste.mozilla.org/4QssuEur)

---

<div class="post-metadata">

**Author:** ![YonSa](https://avatars.discourse-cdn.com/v4/letter/y/53a042/32.png) [@YonSa](https://discourse.scverse.org/u/YonSa)\
**Post date:** [August 7, 2024, 11:10am UTC](https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432/4 "2024-08-07T11:10:09Z")

</div>

This happens with nanostring’s tutorial data as well:

```auto
import squidpy as sq
sample_dir = aux.P.data_dir / 'tutorial_data' / 'Lung5_Rep2/Lung5_Rep2-Flat_files_and_images/'
adata = sq.read.nanostring(
    path=sample_dir,
    counts_file="Lung5_Rep2_exprMat_file.csv",
    meta_file="Lung5_Rep2_metadata_file.csv",
    fov_file="Lung5_Rep2_fov_positions_file.csv",
)
adata = adata.copy() # defragment adata

#%%
sc.pp.normalize_total(adata, inplace=True)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5)
adata = adata[:, adata.var.highly_variable]
sc.tl.pca(adata)
sc.pp.neighbors(adata, n_neighbors=10, n_pcs=40)

```

---

<div class="post-metadata">

**Author:** ![YonSa](https://avatars.discourse-cdn.com/v4/letter/y/53a042/32.png) [@YonSa](https://discourse.scverse.org/u/YonSa)\
**Post date:** [September 3, 2024, 9:58am UTC](https://discourse.scverse.org/t/indexerror-list-index-out-of-range-when-running-sc-pp-neighbors-adata/2432/5 "2024-09-03T09:58:50Z")

</div>

Bump.  
Am I the only one this happens to…?  
I’ve tried with a clean conda env built around squidpy, and running with nanostring’s tutorial data. It looks like the error is coming from somewhere deep in sklearn’s KNN algorithm, but I’m getting the same with previous versions of sklearn as well.
