Skip to content

[pre-commit.ci] pre-commit autoupdate #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[mypy]
python_version = 3.10
plugins = numpy.typing.mypy_plugin

ignore_errors = False
warn_redundant_casts = True
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ ci:
skip: []
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.9
rev: v0.12.8
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
rev: v1.17.1
hooks:
- id: mypy
additional_dependencies: [numpy, types-requests]
Expand Down
1 change: 1 addition & 0 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ def show(
cs_contents.query(f"cs == '{cs}'").iloc[0, :].values.tolist()
)
ax = fig_params.ax if fig_params.axs is None else fig_params.axs[i]
assert isinstance(ax, Axes)

wants_images = False
wants_labels = False
Expand Down
4 changes: 4 additions & 0 deletions src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ def _render_shapes(
vmin = aggregate_with_reduction[0].values if norm.vmin is None else norm.vmin
vmax = aggregate_with_reduction[1].values if norm.vmin is None else norm.vmax
if (norm.vmin is not None or norm.vmax is not None) and norm.vmin == norm.vmax:
assert norm.vmin is not None
assert norm.vmax is not None
# value (vmin=vmax) is placed in the middle of the colorbar so that we can distinguish it from over and
# under values in case clip=True or clip=False with cmap(under)=cmap(0) & cmap(over)=cmap(1)
vmin = norm.vmin - 0.5
Expand Down Expand Up @@ -693,6 +695,8 @@ def _render_points(
vmin = aggregate_with_reduction[0].values if norm.vmin is None else norm.vmin
vmax = aggregate_with_reduction[1].values if norm.vmax is None else norm.vmax
if (norm.vmin is not None or norm.vmax is not None) and norm.vmin == norm.vmax:
assert norm.vmin is not None
assert norm.vmax is not None
# value (vmin=vmax) is placed in the middle of the colorbar so that we can distinguish it from over and
# under values in case clip=True or clip=False with cmap(under)=cmap(0) & cmap(over)=cmap(1)
vmin = norm.vmin - 0.5
Expand Down
33 changes: 24 additions & 9 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ def _prepare_cmap_norm(

cmap = copy(cmap)

assert isinstance(cmap, Colormap), f"Invalid type of `cmap`: {type(cmap)}, expected `Colormap`."

if norm is None:
norm = Normalize(vmin=None, vmax=None, clip=False)

Expand Down Expand Up @@ -2045,30 +2047,41 @@ def _validate_image_render_params(
spatial_element_ch = (
spatial_element.c if isinstance(spatial_element, DataArray) else spatial_element["scale0"].c
)
if (channel := param_dict["channel"]) is not None and (
(isinstance(channel[0], int) and max([abs(ch) for ch in channel]) <= len(spatial_element_ch))
or all(ch in spatial_element_ch for ch in channel)

channel = param_dict["channel"]
channel_list: list[str] | list[int] | None
if isinstance(channel, list):
type_ = type(channel[0])
assert all(isinstance(ch, type_) for ch in channel), "All channels must be of the same type."
# mypy complains that channel_list can be also of type list[str | int]
channel_list = [channel] if isinstance(channel, int | str) else channel # type: ignore[assignment]

if channel_list is not None and (
(isinstance(channel_list[0], int) and max([abs(ch) for ch in channel_list]) <= len(spatial_element_ch)) # type: ignore[arg-type]
or all(ch in spatial_element_ch for ch in channel_list)
):
element_params[el]["channel"] = channel
element_params[el]["channel"] = channel_list
else:
element_params[el]["channel"] = None

element_params[el]["alpha"] = param_dict["alpha"]

if isinstance(palette := param_dict["palette"], list):
if len(palette) == 1:
palette_length = len(channel) if channel is not None else len(spatial_element_ch)
palette_length = len(channel_list) if channel_list is not None else len(spatial_element_ch)
palette = palette * palette_length
if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element_ch):
if (channel_list is not None and len(palette) != len(channel_list)) and len(palette) != len(
spatial_element_ch
):
palette = None
element_params[el]["palette"] = palette
element_params[el]["na_color"] = param_dict["na_color"]

if (cmap := param_dict["cmap"]) is not None:
if len(cmap) == 1:
cmap_length = len(channel) if channel is not None else len(spatial_element_ch)
cmap_length = len(channel_list) if channel_list is not None else len(spatial_element_ch)
cmap = cmap * cmap_length
if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element_ch):
if (channel_list is not None and len(cmap) != len(channel_list)) or len(cmap) != len(spatial_element_ch):
cmap = None
element_params[el]["cmap"] = cmap
element_params[el]["norm"] = param_dict["norm"]
Expand Down Expand Up @@ -2364,7 +2377,9 @@ def _get_datashader_trans_matrix_of_single_element(
# no flipping needed
return tm
# for a Translation, we need the transposed transformation matrix
return tm.T
tm_T = tm.T
assert isinstance(tm_T, np.ndarray)
return tm_T


def _get_transformation_matrix_for_datashader(
Expand Down
Loading