Skip to content

Commit 6ce599f

Browse files
[pre-commit.ci] pre-commit autoupdate (#466)
2 parents c5cb734 + fe3a66e commit 6ce599f

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

.mypy.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[mypy]
22
python_version = 3.10
3-
plugins = numpy.typing.mypy_plugin
43

54
ignore_errors = False
65
warn_redundant_casts = True

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ ci:
99
skip: []
1010
repos:
1111
- repo: https://github.com/rbubley/mirrors-prettier
12-
rev: v3.5.3
12+
rev: v3.6.2
1313
hooks:
1414
- id: prettier
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.11.9
16+
rev: v0.12.8
1717
hooks:
1818
- id: ruff
1919
args: [--fix, --exit-non-zero-on-fix]
2020
- id: ruff-format
2121
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v1.15.0
22+
rev: v1.17.1
2323
hooks:
2424
- id: mypy
2525
additional_dependencies: [numpy, types-requests]

src/spatialdata_plot/pl/basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ def show(
895895
cs_contents.query(f"cs == '{cs}'").iloc[0, :].values.tolist()
896896
)
897897
ax = fig_params.ax if fig_params.axs is None else fig_params.axs[i]
898+
assert isinstance(ax, Axes)
898899

899900
wants_images = False
900901
wants_labels = False

src/spatialdata_plot/pl/render.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ def _render_shapes(
340340
vmin = aggregate_with_reduction[0].values if norm.vmin is None else norm.vmin
341341
vmax = aggregate_with_reduction[1].values if norm.vmin is None else norm.vmax
342342
if (norm.vmin is not None or norm.vmax is not None) and norm.vmin == norm.vmax:
343+
assert norm.vmin is not None
344+
assert norm.vmax is not None
343345
# value (vmin=vmax) is placed in the middle of the colorbar so that we can distinguish it from over and
344346
# under values in case clip=True or clip=False with cmap(under)=cmap(0) & cmap(over)=cmap(1)
345347
vmin = norm.vmin - 0.5
@@ -693,6 +695,8 @@ def _render_points(
693695
vmin = aggregate_with_reduction[0].values if norm.vmin is None else norm.vmin
694696
vmax = aggregate_with_reduction[1].values if norm.vmax is None else norm.vmax
695697
if (norm.vmin is not None or norm.vmax is not None) and norm.vmin == norm.vmax:
698+
assert norm.vmin is not None
699+
assert norm.vmax is not None
696700
# value (vmin=vmax) is placed in the middle of the colorbar so that we can distinguish it from over and
697701
# under values in case clip=True or clip=False with cmap(under)=cmap(0) & cmap(over)=cmap(1)
698702
vmin = norm.vmin - 0.5

src/spatialdata_plot/pl/utils.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ def _prepare_cmap_norm(
526526

527527
cmap = copy(cmap)
528528

529+
assert isinstance(cmap, Colormap), f"Invalid type of `cmap`: {type(cmap)}, expected `Colormap`."
530+
529531
if norm is None:
530532
norm = Normalize(vmin=None, vmax=None, clip=False)
531533

@@ -2045,30 +2047,41 @@ def _validate_image_render_params(
20452047
spatial_element_ch = (
20462048
spatial_element.c if isinstance(spatial_element, DataArray) else spatial_element["scale0"].c
20472049
)
2048-
if (channel := param_dict["channel"]) is not None and (
2049-
(isinstance(channel[0], int) and max([abs(ch) for ch in channel]) <= len(spatial_element_ch))
2050-
or all(ch in spatial_element_ch for ch in channel)
2050+
2051+
channel = param_dict["channel"]
2052+
channel_list: list[str] | list[int] | None
2053+
if isinstance(channel, list):
2054+
type_ = type(channel[0])
2055+
assert all(isinstance(ch, type_) for ch in channel), "All channels must be of the same type."
2056+
# mypy complains that channel_list can be also of type list[str | int]
2057+
channel_list = [channel] if isinstance(channel, int | str) else channel # type: ignore[assignment]
2058+
2059+
if channel_list is not None and (
2060+
(isinstance(channel_list[0], int) and max([abs(ch) for ch in channel_list]) <= len(spatial_element_ch)) # type: ignore[arg-type]
2061+
or all(ch in spatial_element_ch for ch in channel_list)
20512062
):
2052-
element_params[el]["channel"] = channel
2063+
element_params[el]["channel"] = channel_list
20532064
else:
20542065
element_params[el]["channel"] = None
20552066

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

20582069
if isinstance(palette := param_dict["palette"], list):
20592070
if len(palette) == 1:
2060-
palette_length = len(channel) if channel is not None else len(spatial_element_ch)
2071+
palette_length = len(channel_list) if channel_list is not None else len(spatial_element_ch)
20612072
palette = palette * palette_length
2062-
if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element_ch):
2073+
if (channel_list is not None and len(palette) != len(channel_list)) and len(palette) != len(
2074+
spatial_element_ch
2075+
):
20632076
palette = None
20642077
element_params[el]["palette"] = palette
20652078
element_params[el]["na_color"] = param_dict["na_color"]
20662079

20672080
if (cmap := param_dict["cmap"]) is not None:
20682081
if len(cmap) == 1:
2069-
cmap_length = len(channel) if channel is not None else len(spatial_element_ch)
2082+
cmap_length = len(channel_list) if channel_list is not None else len(spatial_element_ch)
20702083
cmap = cmap * cmap_length
2071-
if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element_ch):
2084+
if (channel_list is not None and len(cmap) != len(channel_list)) or len(cmap) != len(spatial_element_ch):
20722085
cmap = None
20732086
element_params[el]["cmap"] = cmap
20742087
element_params[el]["norm"] = param_dict["norm"]
@@ -2364,7 +2377,9 @@ def _get_datashader_trans_matrix_of_single_element(
23642377
# no flipping needed
23652378
return tm
23662379
# for a Translation, we need the transposed transformation matrix
2367-
return tm.T
2380+
tm_T = tm.T
2381+
assert isinstance(tm_T, np.ndarray)
2382+
return tm_T
23682383

23692384

23702385
def _get_transformation_matrix_for_datashader(

0 commit comments

Comments
 (0)