scverse / scverse/scanpy

sc.read_10x_mtx KeyError: 2 The above exception was the direct cause of the following exception:

Open
#3,601 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Please make sure these conditions are met
  • 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 main branch of scanpy.
What happened?

I am using the same code to run other datasets, and it's working fine. However, when I try to run GSE136103, it fails. I'm not sure how to resolve the issue. Could you help me?

Minimal code sample
adata = {}
for i in range(len(dir)):
    data = sc.read_10x_mtx("GSE136103_RAW/" +dir[i], var_names="gene_symbols", cache=True)
    data.var_names_make_unique()  
    adata[dir[i]] = data
    print(dir[i])
    sc.pp.filter_cells(data, min_genes=300)   
    sc.pp.filter_genes(data, min_cells=5)
   
adata = sc.concat(adata,label='sampleid')
adata.obs_names_make_unique()
adata
Error output
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key)
   [3804](https://vscode-remote+ssh-002dremote-002b10-002e146-002e10-002e100.vscode-resource.vscode-cdn.net/home/chenwei/kong/Liver%20data/GSE136103/~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3804) try:
-> [3805](https://vscode-remote+ssh-002dremote-002b10-002e146-002e10-002e100.vscode-resource.vscode-cdn.net/home/chenwei/kong/Liver%20data/GSE136103/~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3805)     return self._engine.get_loc(casted_key)
   [3806](https://vscode-remote+ssh-002dremote-002b10-002e146-002e10-002e100.vscode-resource.vscode-cdn.net/home/chenwei/kong/Liver%20data/GSE136103/~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3806) except KeyError as err:

File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()

File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:2606, in pandas._libs.hashtable.Int64HashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:2630, in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 2

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In[4], [line 4](vscode-notebook-cell:?execution_count=4&line=4)
      [2](vscode-notebook-cell:?execution_count=4&line=2) adata = {}
      [3](vscode-notebook-cell:?execution_count=4&line=3) for i in range(len(dir)):
----> [4](vscode-notebook-cell:?execution_count=4&line=4)     data = sc.read_10x_mtx("GSE136103_RAW/" +dir[i], var_names="gene_symbols", cache=True)
      [5](vscode-notebook-cell:?execution_count=4&line=5)     data.var_names_make_unique()  # var_names 是 基因(feature)的名字
...
   [3815](https://vscode-remote+ssh-002dremote-002b10-002e146-002e10-002e100.vscode-resource.vscode-cdn.net/home/chenwei/kong/Liver%20data/GSE136103/~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3815)     #  InvalidIndexError. Otherwise we fall through and re-raise
   [3816](https://vscode-remote+ssh-002dremote-002b10-002e146-002e10-002e100.vscode-resource.vscode-cdn.net/home/chenwei/kong/Liver%20data/GSE136103/~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3816)     #  the TypeError.
   [3817](https://vscode-remote+ssh-002dremote-002b10-002e146-002e10-002e100.vscode-resource.vscode-cdn.net/home/chenwei/kong/Liver%20data/GSE136103/~/ENTER/envs/scanpy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3817)     self._check_indexing_error(key)

KeyError: 2
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?b6230dbc-deb0-457a-9437-44bcdfc5ea47) or open in a [text editor](command:workbench.action.openLargeOutput?b6230dbc-deb0-457a-9437-44bcdfc5ea47). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
Versions
scanpy==1.10.3 anndata==0.10.8 umap==0.5.7 numpy==1.26.4 scipy==1.11.4 pandas==2.2.3 scikit-learn==1.6.1 statsmodels==0.14.4 igraph==0.11.8 louvain==0.8.2 pynndescent==0.5.13

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 minimal loop at the sc.read_10x_mtx call with the GSE136103_RAW data and the listed package versions. No repository file or test is named; inspect the input layout and full traceback to determine whether this is an input-format incompatibility or a Scanpy bug, with completion defined by a confirmed cause and reproducible resolution.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.