diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8b3406a2..b0fa2abb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,20 +7,24 @@ default_stages: minimum_pre_commit_version: 2.16.0 repos: - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.5.3 + rev: v3.6.2 hooks: - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.7 + rev: v0.14.1 hooks: - id: ruff types_or: [python, pyi, jupyter] args: [--fix, --exit-non-zero-on-fix] - id: ruff-format types_or: [python, pyi, jupyter] + - repo: https://github.com/asottile/blacken-docs + rev: 1.19.1 + hooks: + - id: blacken-docs - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.15.0 + rev: v1.18.2 hooks: - id: mypy - additional_dependencies: [numpy, types-requests] - exclude: tests/|docs/ + additional_dependencies: [numpy, pandas, types-requests] + exclude: tests/|docs/|.scripts/ci/download_data.py|squidpy/datasets/_(dataset|image).py diff --git a/src/squidpy/pl/_interactive/_model.py b/src/squidpy/pl/_interactive/_model.py index 4856dc09..a05b2bd0 100644 --- a/src/squidpy/pl/_interactive/_model.py +++ b/src/squidpy/pl/_interactive/_model.py @@ -102,7 +102,7 @@ def _set_library(self) -> None: self.library_id = [self.library_id] self.library_id, _ = _unique_order_preserving(self.library_id) # type: ignore[assignment] - if not len(self.library_id): + if self.library_id is None or not len(self.library_id): raise ValueError("No library ids have been selected.") # invalid library ids from adata are filtered below # invalid library ids from container raise KeyError in `__post_init__` after this call diff --git a/src/squidpy/pl/_spatial_utils.py b/src/squidpy/pl/_spatial_utils.py index 89859ff9..9da0e1ad 100644 --- a/src/squidpy/pl/_spatial_utils.py +++ b/src/squidpy/pl/_spatial_utils.py @@ -6,7 +6,7 @@ from functools import partial from numbers import Number from types import MappingProxyType -from typing import TYPE_CHECKING, Any, Literal, NamedTuple, Optional, TypeAlias, Union +from typing import TYPE_CHECKING, Any, Literal, NamedTuple, TypeAlias, cast import dask.array as da import numpy as np @@ -842,12 +842,18 @@ def _prepare_params_plot( fig, ax = plt.subplots(figsize=figsize, dpi=dpi, constrained_layout=True) # set cmap and norm + if cmap is None: - cmap = plt.rcParams["image.cmap"] - if isinstance(cmap, str): - cmap = plt.colormaps[cmap] - cmap.set_bad("lightgray" if na_color is None else na_color) + cmap_name: str = str(plt.rcParams["image.cmap"]) + cmap_obj = plt.get_cmap(cmap_name) + elif isinstance(cmap, str): + cmap_obj = plt.get_cmap(cmap) + else: + cmap_obj = cmap # already a Colormap + + cmap_obj.set_bad("lightgray" if na_color is None else na_color) + # build norm as before... if isinstance(norm, Normalize): pass elif vcenter is None: @@ -863,7 +869,7 @@ def _prepare_params_plot( scalebar_dx, scalebar_units = _get_scalebar(scalebar_dx, scalebar_units, len(spatial_params.library_id)) fig_params = FigParams(fig, ax, axs, iter_panels, title, ax_labels, frameon) - cmap_params = CmapParams(cmap, img_cmap, norm) + cmap_params = CmapParams(cmap_obj, img_cmap, norm) scalebar_params = ScalebarParams(scalebar_dx, scalebar_units) return fig_params, cmap_params, scalebar_params, kwargs