Skip to content

read_10x_mtx cannot deal with numerical gene symbols #3909

@arteymix

Description

@arteymix

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?

The read_10x_mtx function uses Pandas' defaults for reading tabular data which results in numerical gene IDs such as NCBI gene IDs to be interpreted as number. This does not work with make_unique=True because it will attempt to concatenate a unique suffix to a float.

Minimal code sample

import scanpy
a = scanpy.read_10x_mtx('./GSE227313/1505436_Sorted_vHipp_D1_replicateB', var_names='gene_ids')

Error output

/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/anndata/_core/anndata.py:865: UserWarning: 
AnnData expects .var.index to contain strings, but got values like:
    [109979, 18952, 109978, 18950, 18951]
    Inferred to be: integer
  names = self._prep_dim_index(names, "var")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/legacy_api_wrap/__init__.py", line 88, in fn_compatible
    return fn(*args_all, **kw)
  File "/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/scanpy/readwrite.py", line 582, in read_10x_mtx
    return adata[:, gex_rows].copy()
           ~~~~~^^^^^^^^^^^^^
  File "/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/anndata/_core/anndata.py", line 1049, in __getitem__
    oidx, vidx = self._normalize_indices(index)
                 ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/anndata/_core/anndata.py", line 1030, in _normalize_indices
    return _normalize_indices(index, self.obs_names, self.var_names)
  File "/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/anndata/_core/index.py", line 36, in _normalize_indices
    ax1 = _normalize_index(ax1, names1)
  File "/home/guillaume/Projets/gemmapy/.venv/lib64/python3.14/site-packages/anndata/_core/index.py", line 46, in _normalize_index
    raise TypeError(msg)
TypeError: Don’t call _normalize_index with non-categorical/string names and non-range index Index([   109979,     18952,    109978,     18950,     18951,    108645,
       102640821, 102640825,    626832,    626834,
       ...
           19263,     19264, 100043034,     19261,     20248,     19262,
           20249,     19260,    403088, 100043033],
      dtype='int64', length=24428)

Versions

Details
scanpy	1.11.5
----	----
matplotlib	3.10.7
scipy	1.16.3
PyYAML	6.0.3
joblib	1.5.2
pandas	2.3.3
cycler	0.12.1
natsort	8.4.0
scikit-learn	1.7.2
threadpoolctl	3.6.0
typing	3.10.0.0
llvmlite	0.46.0
numpy	2.3.5
donfig	0.8.1.post1
anndata	0.12.6
session-info2	0.2.3
pytz	2025.2
typing_extensions	4.15.0
numcodecs	0.16.5
pillow	12.0.0
pyparsing	3.2.5
legacy-api-wrap	1.5
packaging	25.0
h5py	3.15.1
kiwisolver	1.4.9
six	1.17.0
python-dateutil	2.9.0.post0
setuptools	80.9.0
zarr	3.1.5
numba	0.63.0
google-crc32c	1.7.1
----	----
Python	3.14.0 (main, Oct 17 2025, 00:00:00) [GCC 15.2.1 20251022 (Red Hat 15.2.1-3)]
OS	Linux-6.17.9-300.fc43.x86_64-x86_64-with-glibc2.42
CPU	16 logical CPU cores
GPU	No GPU found
Updated	2025-12-09 23:51

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions