Skip to content

fix: import scanpy default palettes across scanpy versions (1.13 compat) - #759

Merged
timtreis merged 1 commit into
mainfrom
fix/scanpy113-palettes-import
Aug 7, 2026
Merged

fix: import scanpy default palettes across scanpy versions (1.13 compat)#759
timtreis merged 1 commit into
mainfrom
fix/scanpy113-palettes-import

Conversation

@timtreis

@timtreis timtreis commented Aug 7, 2026

Copy link
Copy Markdown
Member

Problem

The py3.14-pre CI env installs pre-release scanpy 1.13.0a1, where import spatialdata_plot crashes at collection:

src/spatialdata_plot/pl/_palette.py:23: in <module>
    from scanpy.plotting.palettes import default_20, default_28, default_102
E   ModuleNotFoundError: No module named 'scanpy.plotting.palettes'

Every test in that env errors at conftest.py import.

Root cause

scanpy 1.13 relocated the default categorical palettes from scanpy.plotting.palettes to scanpy.plotting.legacy.palettes (no surviving sc.pl.palettes alias). spatialdata-plot imported the old path in three modules (_palette.py, _color.py, utils.py).

Fix

Add a single _scanpy_palettes shim that imports from the new path and falls back to the old one, and point all three modules at it:

try:  # scanpy >= 1.13
    from scanpy.plotting.legacy.palettes import default_20, default_28, default_102
except ImportError:  # scanpy < 1.13
    from scanpy.plotting.palettes import default_20, default_28, default_102

The palette values are frozendefault_20/28/102 hash identically across scanpy 1.11.4 and 1.13.0a1 — so behavior is unchanged; this only makes the import resilient to the relocation.

Verification

  • Shim resolves on stable 1.11.4 (fallback path) and pre-release 1.13.0a1 (new path); both yield 20/28/102 colors.
  • import spatialdata_plot succeeds; test_palette.py (41) green locally.

Notes

py3.14-pre is continue-on-error (non-gating), so this is a forward-looking fix for scanpy 1.13 readiness rather than a merge blocker.

scanpy 1.13 relocated default_20/default_28/default_102 from
scanpy.plotting.palettes to scanpy.plotting.legacy.palettes, breaking
`import spatialdata_plot` on pre-release scanpy (every test in the
py3.14-pre env errored at conftest collection).

Centralize the three duplicated imports into a single _scanpy_palettes
shim that tries the new path and falls back to the old one, and point
_palette.py, _color.py and utils.py at it. The palette values are frozen
(identical across scanpy versions), so behavior is unchanged.
@timtreis
timtreis merged commit c6054fb into main Aug 7, 2026
4 of 8 checks passed
@timtreis
timtreis deleted the fix/scanpy113-palettes-import branch August 7, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant