Skip to content

Commit ed66c85

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3a54f45 commit ed66c85

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/spatialdata_plot/pl/utils.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import pandas as pd
2525
import shapely
2626
import spatialdata as sd
27-
import xarray as xr
2827
from anndata import AnnData
2928
from cycler import Cycler, cycler
3029
from datashader.core import Canvas
@@ -325,8 +324,11 @@ def _as_rgba_array(x: Any) -> np.ndarray:
325324
return ColorConverter().to_rgba_array(x)
326325

327326
# Case A: per-row numeric colors given as Nx3 or Nx4 float array
328-
if c_arr.ndim == 2 and c_arr.shape[0] == len(shapes) and c_arr.shape[1] in (3, 4) and np.issubdtype(
329-
c_arr.dtype, np.number
327+
if (
328+
c_arr.ndim == 2
329+
and c_arr.shape[0] == len(shapes)
330+
and c_arr.shape[1] in (3, 4)
331+
and np.issubdtype(c_arr.dtype, np.number)
330332
):
331333
fill_c = _as_rgba_array(c_arr)
332334

@@ -352,7 +354,7 @@ def _as_rgba_array(x: Any) -> np.ndarray:
352354
fill_c[:] = na_rgba
353355
if finite_mask.any():
354356
fill_c[finite_mask] = cmap(used_norm(c_arr[finite_mask]))
355-
357+
356358
elif c_arr.ndim == 1 and len(c_arr) == len(shapes) and c_arr.dtype == object:
357359
# Split into numeric vs color-like
358360
s = pd.Series(c_arr, copy=False)
@@ -435,7 +437,9 @@ def _process_point(row: pd.Series, scale: float) -> dict[str, Any]:
435437
"geometry": mpatches.Circle((row["geometry"].x, row["geometry"].y), radius=row["radius"] * scale),
436438
}
437439

438-
def _create_patches(shapes_df_: GeoDataFrame, fill_colors: list[Any], outline_colors: list[Any], scale: float) -> pd.DataFrame:
440+
def _create_patches(
441+
shapes_df_: GeoDataFrame, fill_colors: list[Any], outline_colors: list[Any], scale: float
442+
) -> pd.DataFrame:
439443
rows: list[dict[str, Any]] = []
440444
is_multiple = len(shapes_df_) > 1
441445
for idx, row in shapes_df_.iterrows():
@@ -1765,9 +1769,7 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
17651769
if (norm := param_dict.get("norm")) is not None:
17661770
if element_type in {"images", "labels"} and not isinstance(norm, Normalize):
17671771
raise TypeError("Parameter 'norm' must be of type Normalize.")
1768-
if element_type in {"shapes", "points"} and not isinstance(
1769-
norm, bool | Normalize
1770-
):
1772+
if element_type in {"shapes", "points"} and not isinstance(norm, bool | Normalize):
17711773
raise TypeError("Parameter 'norm' must be a boolean or a mpl.Normalize.")
17721774

17731775
if (scale := param_dict.get("scale")) is not None:
@@ -1786,15 +1788,11 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
17861788
raise ValueError("Parameter 'size' must be a positive number.")
17871789

17881790
if element_type == "shapes" and (shape := param_dict.get("shape")) is not None:
1789-
valid_shapes = {"circle", "hex", "visium_hex", "square"}
1791+
valid_shapes = {"circle", "hex", "visium_hex", "square"}
17901792
if not isinstance(shape, str):
1791-
raise TypeError(
1792-
f"Parameter 'shape' must be a String from {valid_shapes} if not None."
1793-
)
1793+
raise TypeError(f"Parameter 'shape' must be a String from {valid_shapes} if not None.")
17941794
if shape not in valid_shapes:
1795-
raise ValueError(
1796-
f"'{shape}' is not supported for 'shape', please choose from {valid_shapes}."
1797-
)
1795+
raise ValueError(f"'{shape}' is not supported for 'shape', please choose from {valid_shapes}.")
17981796

17991797
table_name = param_dict.get("table_name")
18001798
table_layer = param_dict.get("table_layer")
@@ -2568,6 +2566,7 @@ def _hex_no_alpha(hex: str) -> str:
25682566

25692567
raise ValueError("Invalid hex color length: must be either '#RRGGBB' or '#RRGGBBAA'")
25702568

2569+
25712570
def _convert_shapes(
25722571
shapes: GeoDataFrame,
25732572
target_shape: str,
@@ -2749,7 +2748,6 @@ def _multipolygon_to_visium_hex(multipolygon: shapely.MultiPolygon) -> tuple[sha
27492748
return shapes
27502749

27512750

2752-
27532751
def _convert_alpha_to_datashader_range(alpha: float) -> float:
27542752
"""Convert alpha from the range [0, 1] to the range [0, 255] used in datashader."""
27552753
# prevent a value of 255, bc that led to fully colored test plots instead of just colored points/shapes

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,4 @@ def sdata_hexagonal_grid_spots():
551551
# Use ShapesModel.parse() to create a properly validated GeoDataFrame
552552
shapes_gdf = ShapesModel.parse(gdf)
553553

554-
return SpatialData(shapes={"spots": shapes_gdf})
554+
return SpatialData(shapes={"spots": shapes_gdf})

0 commit comments

Comments
 (0)