From b0c1cde0baec715b7a3bf79f8058eafb232b8a17 Mon Sep 17 00:00:00 2001 From: anon Date: Fri, 8 May 2026 23:48:33 +0200 Subject: [PATCH] Raise ValueError on invalid scale in render_images Previously, render_images(scale="...") silently reset an unknown scale name to None and auto-picked a resolution, discarding the user's intent without warning. The downstream _multiscale_to_spatial_image already had the right ValueError but was unreachable because the value was cleared beforehand. Validate at the entry point and surface the error with the list of valid scales. Closes #623 --- src/spatialdata_plot/pl/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index 6971f31a..867b3cfb 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -3007,12 +3007,12 @@ def _validate_image_render_params( element_params[el]["norm"] = norm scale = param_dict["scale"] if scale and isinstance(param_dict["sdata"][el], DataTree): - if scale not in list(param_dict["sdata"][el].keys()) and scale != "full": - element_params[el]["scale"] = None - else: - element_params[el]["scale"] = scale - else: - element_params[el]["scale"] = scale + valid_scales = list(param_dict["sdata"][el].keys()) + if scale not in valid_scales and scale != "full": + raise ValueError( + f"Scale '{scale}' does not exist in image '{el}'. Valid scales: {valid_scales + ['full']}." + ) + element_params[el]["scale"] = scale element_params[el]["colorbar"] = param_dict["colorbar"] element_params[el]["colorbar_params"] = param_dict["colorbar_params"]