Skip to content

Commit 35014ff

Browse files
timtreisclaude
andcommitted
Extract warning constant and align na_color override with points
- Extract duplicated groups-ignored warning string to _GROUPS_IGNORED_WARNING - Add col_for_color guard to na_color override, matching the points pattern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 203d6ae commit 35014ff

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/spatialdata_plot/pl/render.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,11 @@ def _render_labels(
13141314

13151315
_, trans_data = _prepare_transformation(label, coordinate_system, ax)
13161316

1317-
na_color = render_params.color if render_params.color is not None else render_params.cmap_params.na_color
1317+
na_color = (
1318+
render_params.color
1319+
if col_for_color is None and render_params.color is not None
1320+
else render_params.cmap_params.na_color
1321+
)
13181322
color_source_vector, color_vector, categorical = _set_color_source_vec(
13191323
sdata=sdata_filt,
13201324
element=label,

src/spatialdata_plot/pl/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
# once https://github.com/scverse/spatialdata/pull/689/ is in a release
9595
ColorLike = tuple[float, ...] | list[float] | str
9696

97+
_GROUPS_IGNORED_WARNING = "Parameter 'groups' is ignored when 'color' is a literal color, not a column name."
98+
9799

98100
def _extract_scalar_value(value: Any, default: float = 0.0) -> float:
99101
"""
@@ -2474,7 +2476,7 @@ def _validate_label_render_params(
24742476
has_col = element_params[el]["col_for_color"] is not None
24752477
element_params[el]["palette"] = param_dict["palette"] if has_col else None
24762478
if not has_col and param_dict["groups"] is not None:
2477-
logger.warning("Parameter 'groups' is ignored when 'color' is a literal color, not a column name.")
2479+
logger.warning(_GROUPS_IGNORED_WARNING)
24782480
element_params[el]["groups"] = param_dict["groups"] if has_col else None
24792481
element_params[el]["colorbar"] = param_dict["colorbar"]
24802482
element_params[el]["colorbar_params"] = param_dict["colorbar_params"]
@@ -2544,7 +2546,7 @@ def _validate_points_render_params(
25442546

25452547
element_params[el]["palette"] = param_dict["palette"] if param_dict["col_for_color"] is not None else None
25462548
if param_dict["col_for_color"] is None and param_dict["groups"] is not None:
2547-
logger.warning("Parameter 'groups' is ignored when 'color' is a literal color, not a column name.")
2549+
logger.warning(_GROUPS_IGNORED_WARNING)
25482550
element_params[el]["groups"] = param_dict["groups"] if param_dict["col_for_color"] is not None else None
25492551
element_params[el]["ds_reduction"] = param_dict["ds_reduction"]
25502552
element_params[el]["colorbar"] = param_dict["colorbar"]
@@ -2630,7 +2632,7 @@ def _validate_shape_render_params(
26302632

26312633
element_params[el]["palette"] = param_dict["palette"] if param_dict["col_for_color"] is not None else None
26322634
if param_dict["col_for_color"] is None and param_dict["groups"] is not None:
2633-
logger.warning("Parameter 'groups' is ignored when 'color' is a literal color, not a column name.")
2635+
logger.warning(_GROUPS_IGNORED_WARNING)
26342636
element_params[el]["groups"] = param_dict["groups"] if param_dict["col_for_color"] is not None else None
26352637
element_params[el]["method"] = param_dict["method"]
26362638
element_params[el]["ds_reduction"] = param_dict["ds_reduction"]

0 commit comments

Comments
 (0)