Skip to content

Commit dbc66de

Browse files
authored
Merge branch 'main' into feature/202306_support_multipolygons
2 parents b75c743 + b84c1ab commit dbc66de

File tree

6 files changed

+30
-33
lines changed

6 files changed

+30
-33
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ repos:
1313
hooks:
1414
- id: black
1515
- repo: https://github.com/pre-commit/mirrors-prettier
16-
rev: v3.0.0-alpha.6
16+
rev: v3.0.0-alpha.9-for-vscode
1717
hooks:
1818
- id: prettier
1919
- repo: https://github.com/asottile/blacken-docs
2020
rev: 1.13.0
2121
hooks:
2222
- id: blacken-docs
2323
- repo: https://github.com/pre-commit/mirrors-mypy
24-
rev: v1.2.0
24+
rev: v1.3.0
2525
hooks:
2626
- id: mypy
2727
additional_dependencies: [numpy, types-requests]
2828
exclude: tests/|docs/
2929
- repo: https://github.com/charliermarsh/ruff-pre-commit
30-
rev: v0.0.261
30+
rev: v0.0.272
3131
hooks:
3232
- id: ruff
3333
args: [--fix, --exit-non-zero-on-fix]

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,3 @@ target-version = "py39"
161161
"src/spatialdata_plot/pl/utils.py"= ["PGH003"]
162162
[tool.ruff.pydocstyle]
163163
convention = "numpy"
164-
[tool.ruff.pyupgrade]
165-
# Preserve types, even if a file imports `from __future__ import annotations`.
166-
keep-runtime-typing = true

src/spatialdata_plot/pl/basic.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections import OrderedDict
55
from collections.abc import Sequence
66
from pathlib import Path
7-
from typing import Any, Optional, Union
7+
from typing import Any
88

99
import matplotlib.pyplot as plt
1010
import scanpy as sc
@@ -82,11 +82,11 @@ def __init__(self, sdata: sd.SpatialData) -> None:
8282

8383
def _copy(
8484
self,
85-
images: Union[None, dict[str, Union[SpatialImage, MultiscaleSpatialImage]]] = None,
86-
labels: Union[None, dict[str, Union[SpatialImage, MultiscaleSpatialImage]]] = None,
87-
points: Union[None, dict[str, DaskDataFrame]] = None,
88-
shapes: Union[None, dict[str, GeoDataFrame]] = None,
89-
table: Union[None, AnnData] = None,
85+
images: None | dict[str, SpatialImage | MultiscaleSpatialImage] = None,
86+
labels: None | dict[str, SpatialImage | MultiscaleSpatialImage] = None,
87+
points: None | dict[str, DaskDataFrame] = None,
88+
shapes: None | dict[str, GeoDataFrame] = None,
89+
table: None | AnnData = None,
9090
) -> sd.SpatialData:
9191
"""Copy the current `SpatialData` object, optionally modifying some of its attributes.
9292
@@ -150,7 +150,7 @@ def render_shapes(
150150
layer: str | None = None,
151151
palette: Palette_t = None,
152152
cmap: Colormap | str | None = None,
153-
norm: Optional[Normalize] = None,
153+
norm: None | Normalize = None,
154154
na_color: str | tuple[float, ...] | None = "lightgrey",
155155
outline_alpha: float = 1.0,
156156
fill_alpha: float = 1.0,
@@ -232,7 +232,7 @@ def render_points(
232232
size: float = 1.0,
233233
palette: Palette_t = None,
234234
cmap: Colormap | str | None = None,
235-
norm: Optional[Normalize] = None,
235+
norm: None | Normalize = None,
236236
na_color: str | tuple[float, ...] | None = (0.0, 0.0, 0.0, 0.0),
237237
alpha: float = 1.0,
238238
**kwargs: Any,
@@ -296,7 +296,7 @@ def render_images(
296296
elements: str | list[str] | None = None,
297297
channel: list[str] | list[int] | int | str | None = None,
298298
cmap: Colormap | str | None = None,
299-
norm: Optional[Normalize] = None,
299+
norm: None | Normalize = None,
300300
na_color: str | tuple[float, ...] | None = (0.0, 0.0, 0.0, 0.0),
301301
palette: Palette_t = None,
302302
alpha: float = 1.0,
@@ -358,7 +358,7 @@ def render_labels(
358358
layer: str | None = None,
359359
palette: Palette_t = None,
360360
cmap: Colormap | str | None = None,
361-
norm: Optional[Normalize] = None,
361+
norm: None | Normalize = None,
362362
na_color: str | tuple[float, ...] | None = (0.0, 0.0, 0.0, 0.0),
363363
outline_alpha: float = 1.0,
364364
fill_alpha: float = 0.3,
@@ -452,11 +452,11 @@ def show(
452452
figsize: tuple[float, float] | None = None,
453453
dpi: int | None = None,
454454
fig: Figure | None = None,
455-
title: Optional[Union[str, Sequence[str]]] = None,
455+
title: None | str | Sequence[str] = None,
456456
share_extent: bool = True,
457457
ax: Axes | Sequence[Axes] | None = None,
458458
return_ax: bool = False,
459-
save: Optional[Union[str, Path]] = None,
459+
save: None | str | Path = None,
460460
) -> sd.SpatialData:
461461
"""
462462
Plot the images in the SpatialData object.
@@ -517,7 +517,7 @@ def show(
517517
if isinstance(title, str):
518518
title = [title]
519519

520-
if not all([isinstance(t, str) for t in title]):
520+
if not all(isinstance(t, str) for t in title):
521521
raise TypeError("All titles must be strings.")
522522

523523
# Simplicstic solution: If the images are multiscale, just use the first

src/spatialdata_plot/pl/render.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def _get_collection_shape(
115115
c: Any,
116116
s: float,
117117
norm: Any,
118-
fill_alpha: Optional[float] = None,
119-
outline_alpha: Optional[float] = None,
118+
fill_alpha: None | float = None,
119+
outline_alpha: None | float = None,
120120
**kwargs: Any,
121121
) -> PatchCollection:
122122
polygon_df = shapes[shapes["geometry"].apply(lambda geom: geom.geom_type == "Polygon")]

src/spatialdata_plot/pl/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _prepare_params_plot(
112112
fig, grid = _panel_grid(
113113
num_panels=num_panels, hspace=hspace, wspace=wspace, ncols=ncols, dpi=dpi, figsize=figsize
114114
)
115-
axs: Union[Sequence[Axes], None] = [plt.subplot(grid[c]) for c in range(num_panels)]
115+
axs: None | Sequence[Axes] = [plt.subplot(grid[c]) for c in range(num_panels)]
116116
elif num_panels > 1 and ax is not None:
117117
if len(ax) != num_panels:
118118
raise ValueError(f"Len of `ax`: {len(ax)} is not equal to number of panels: {num_panels}.")
@@ -151,10 +151,10 @@ def _get_cs_contents(sdata: sd.SpatialData) -> pd.DataFrame:
151151

152152
for cs_name, element_ids in cs_mapping.items():
153153
# determine if coordinate system has the respective elements
154-
cs_has_images = bool(any([(e in sdata.images) for e in element_ids]))
155-
cs_has_labels = bool(any([(e in sdata.labels) for e in element_ids]))
156-
cs_has_points = bool(any([(e in sdata.points) for e in element_ids]))
157-
cs_has_shapes = bool(any([(e in sdata.shapes) for e in element_ids]))
154+
cs_has_images = bool(any((e in sdata.images) for e in element_ids))
155+
cs_has_labels = bool(any((e in sdata.labels) for e in element_ids))
156+
cs_has_points = bool(any((e in sdata.points) for e in element_ids))
157+
cs_has_shapes = bool(any((e in sdata.shapes) for e in element_ids))
158158

159159
cs_contents = pd.concat(
160160
[
@@ -181,7 +181,7 @@ def _get_cs_contents(sdata: sd.SpatialData) -> pd.DataFrame:
181181

182182
def _get_extent(
183183
sdata: sd.SpatialData,
184-
coordinate_systems: Optional[Union[str, Sequence[str]]] = None,
184+
coordinate_systems: None | str | Sequence[str] = None,
185185
has_images: bool = True,
186186
has_labels: bool = True,
187187
has_points: bool = True,
@@ -480,7 +480,7 @@ class OutlineParams:
480480
gap_size: float
481481
gap_color: str
482482
bg_size: float
483-
bg_color: Union[str, tuple[float, ...]]
483+
bg_color: str | tuple[float, ...]
484484

485485

486486
def _set_outline(
@@ -504,7 +504,7 @@ def _set_outline(
504504
return OutlineParams(outline, gap_size, gap_color, bg_size, bg_color)
505505

506506

507-
def _get_subplots(num_images: int, ncols: int = 4, width: int = 4, height: int = 3) -> Union[plt.Figure, plt.Axes]:
507+
def _get_subplots(num_images: int, ncols: int = 4, width: int = 4, height: int = 3) -> plt.Figure | plt.Axes:
508508
"""Set up the axs objects.
509509
510510
Parameters
@@ -630,7 +630,7 @@ def _normalize(
630630
return norm
631631

632632

633-
def _get_colors_for_categorical_obs(categories: Sequence[Union[str, int]], palette: Palette_t = None) -> list[str]:
633+
def _get_colors_for_categorical_obs(categories: Sequence[str | int], palette: Palette_t = None) -> list[str]:
634634
"""
635635
Return a list of colors for a categorical observation.
636636
@@ -771,7 +771,7 @@ def _map_color_seg(
771771
def _get_palette(
772772
categories: Sequence[Any],
773773
adata: AnnData | None = None,
774-
cluster_key: Optional[str] | None = None,
774+
cluster_key: None | str = None,
775775
palette: Palette_t = None,
776776
alpha: float = 1.0,
777777
) -> Mapping[str, str] | None:
@@ -1082,7 +1082,7 @@ def _flatten_transformation_sequence(
10821082
transformations = list(transformation_sequence.transformations)
10831083
found_bottom_of_tree = False
10841084
while not found_bottom_of_tree:
1085-
if all([not isinstance(t, sd.transformations.transformations.Sequence) for t in transformations]):
1085+
if all(not isinstance(t, sd.transformations.transformations.Sequence) for t in transformations):
10861086
found_bottom_of_tree = True
10871087
else:
10881088
for idx, t in enumerate(transformations):

src/spatialdata_plot/pp/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_elements(self, elements: Union[str, list[str]]) -> sd.SpatialData:
116116
if not isinstance(elements, (str, list)):
117117
raise TypeError("Parameter 'elements' must be a string or a list of strings.")
118118

119-
if not all([isinstance(e, str) for e in elements]):
119+
if not all(isinstance(e, str) for e in elements):
120120
raise TypeError("When parameter 'elements' is a list, all elements must be strings.")
121121

122122
if isinstance(elements, str):

0 commit comments

Comments
 (0)