Skip to content

Commit 3e793f7

Browse files
committed
updated tests
1 parent 94d2eca commit 3e793f7

File tree

6 files changed

+288
-154
lines changed

6 files changed

+288
-154
lines changed

src/spatialdata_plot/pl/basic.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import sys
4-
import warnings
54
from collections import OrderedDict
65
from copy import deepcopy
76
from pathlib import Path
@@ -23,6 +22,7 @@
2322
from xarray import DataArray, DataTree
2423

2524
from spatialdata_plot._accessor import register_spatial_data_accessor
25+
from spatialdata_plot._logging import logger
2626
from spatialdata_plot.pl.render import (
2727
_render_images,
2828
_render_labels,
@@ -272,11 +272,7 @@ def render_shapes(
272272
"""
273273
# TODO add Normalize object in tutorial notebook and point to that notebook here
274274
if "vmin" in kwargs or "vmax" in kwargs:
275-
warnings.warn(
276-
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
277-
DeprecationWarning,
278-
stacklevel=2,
279-
)
275+
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
280276
params_dict = _validate_shape_render_params(
281277
self._sdata,
282278
element=element,
@@ -423,11 +419,7 @@ def render_points(
423419
"""
424420
# TODO add Normalize object in tutorial notebook and point to that notebook here
425421
if "vmin" in kwargs or "vmax" in kwargs:
426-
warnings.warn(
427-
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
428-
DeprecationWarning,
429-
stacklevel=2,
430-
)
422+
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
431423
params_dict = _validate_points_render_params(
432424
self._sdata,
433425
element=element,
@@ -544,11 +536,7 @@ def render_images(
544536
"""
545537
# TODO add Normalize object in tutorial notebook and point to that notebook here
546538
if "vmin" in kwargs or "vmax" in kwargs:
547-
warnings.warn(
548-
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
549-
DeprecationWarning,
550-
stacklevel=2,
551-
)
539+
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
552540
params_dict = _validate_image_render_params(
553541
self._sdata,
554542
element=element,
@@ -679,11 +667,7 @@ def render_labels(
679667
"""
680668
# TODO add Normalize object in tutorial notebook and point to that notebook here
681669
if "vmin" in kwargs or "vmax" in kwargs:
682-
warnings.warn(
683-
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
684-
DeprecationWarning,
685-
stacklevel=2,
686-
)
670+
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
687671
params_dict = _validate_label_render_params(
688672
self._sdata,
689673
element=element,
@@ -918,9 +902,7 @@ def show(
918902
# go through tree
919903

920904
for i, cs in enumerate(coordinate_systems):
921-
with warnings.catch_warnings():
922-
warnings.filterwarnings("ignore", category=UserWarning)
923-
sdata = self._copy()
905+
sdata = self._copy()
924906
_, has_images, has_labels, has_points, has_shapes = (
925907
cs_contents.query(f"cs == '{cs}'").iloc[0, :].values.tolist()
926908
)
@@ -1000,16 +982,12 @@ def show(
1000982
assert isinstance(params_copy.color, str)
1001983
colors = sc.get.obs_df(sdata[table], [params_copy.color])
1002984
if isinstance(colors[params_copy.color].dtype, pd.CategoricalDtype):
1003-
# Avoid mutating `.uns` by generating new colors implicitly.
1004-
# Only copy colors if they already exist in `.uns`.
1005-
color_key = f"{params_copy.color}_colors"
1006-
if color_key in sdata[table].uns:
1007-
_maybe_set_colors(
1008-
source=sdata[table],
1009-
target=sdata[table],
1010-
key=params_copy.color,
1011-
palette=params_copy.palette,
1012-
)
985+
_maybe_set_colors(
986+
source=sdata[table],
987+
target=sdata[table],
988+
key=params_copy.color,
989+
palette=params_copy.palette,
990+
)
1013991

1014992
rasterize = (params_copy.scale is None) or (
1015993
isinstance(params_copy.scale, str)

src/spatialdata_plot/pl/render.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ def _render_shapes(
147147
color_vector = np.asarray(color_vector, dtype=float)
148148
if np.isnan(color_vector).any():
149149
nan_count = int(np.isnan(color_vector).sum())
150-
logger.warning(
151-
f"Found {nan_count} NaN values in color data. These observations will be colored with the 'na_color'."
152-
)
150+
msg = f"Found {nan_count} NaN values in color data. These observations will be colored with the 'na_color'."
151+
warnings.warn(msg, UserWarning, stacklevel=2)
152+
logger.warning(msg)
153153

154154
# Using dict.fromkeys here since set returns in arbitrary order
155155
# remove the color of NaN values, else it might be assigned to a category
@@ -656,12 +656,14 @@ def _render_points(
656656
cols = sc.get.obs_df(adata, [col_for_color])
657657
# maybe set color based on type
658658
if isinstance(cols[col_for_color].dtype, pd.CategoricalDtype):
659-
_maybe_set_colors(
660-
source=adata,
661-
target=adata,
662-
key=col_for_color,
663-
palette=palette,
664-
)
659+
uns_color_key = f"{col_for_color}_colors"
660+
if uns_color_key in adata.uns:
661+
_maybe_set_colors(
662+
source=adata,
663+
target=adata,
664+
key=col_for_color,
665+
palette=palette,
666+
)
665667

666668
# when user specified a single color, we emulate the form of `na_color` and use it
667669
default_color = (
@@ -778,7 +780,7 @@ def _render_points(
778780
agg = agg.where((agg <= norm.vmin) | (np.isnan(agg)), other=2)
779781
agg = agg.where((agg != norm.vmin) | (np.isnan(agg)), other=0.5)
780782

781-
color_key = (
783+
color_key: list[str] | None = (
782784
list(color_vector.categories.values)
783785
if (type(color_vector) is pd.core.arrays.categorical.Categorical)
784786
and (len(color_vector.categories.values) > 1)

0 commit comments

Comments
 (0)