Skip to content

scanpy plot #3617

@WeihangChen0

Description

@WeihangChen0

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?

Dear development group of Scanpy,
I've encountered an issue when trying to plot umap using a column stored in anndata.obs['leiden5'] as the color. A pandas indexing error appeared as pasted in code session below. Similar error related to pandas has been reported before in packages other than scanpy but I cannot find a workable solution for scanpy related question. The package version would be python==3.10 scanpy==1.10.2 anndata==0.10.9 numpy==1.26.4 pandas==2.2.2 .

Forgive me for asking for solution under this version of scanpy and pandas as there is an important package I'm currently using depends on the older version of scanpy and pandas. If this problem has been resolved in scanpy in the newer version, I shall try to find other resolution as well.

Regards,
Weihang

Minimal code sample

>> sc.pl.umap(adata0, color="leiden5", save="leiden5_umap.png")

Error output

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc
    return self._engine.get_loc(casted_key)
  File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc
  File "index.pyx", line 173, in pandas._libs.index.IndexEngine.get_loc
TypeError: '(slice(None, None, None), (0, 1))' is an invalid key

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.10/site-packages/scanpy/plotting/_tools/scatterplots.py", line 690, in umap
    return embedding(adata, "umap", **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/scanpy/plotting/_tools/scatterplots.py", line 308, in embedding
    coords = basis_values[:, dims][order, :]
  File "/opt/conda/lib/python3.10/site-packages/pandas/core/frame.py", line 4102, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3817, in get_loc
    self._check_indexing_error(key)
  File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 6059, in _check_indexing_error
    raise InvalidIndexError(key)
pandas.errors.InvalidIndexError: (slice(None, None, None), (0, 1))

Versions

python==3.10 scanpy==1.10.2 anndata==0.10.9 numpy==1.26.4 pandas==2.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions