From d192b790d44652f777f6fdc4fc87ec348cd3286f Mon Sep 17 00:00:00 2001 From: Tim Treis Date: Fri, 24 Apr 2026 22:57:56 +0200 Subject: [PATCH 1/2] Warn and render na_color when color column is all-NaN (#599) Previously an all-NaN color column raised a misleading ValueError that blamed instance-id alignment even when the join succeeded. Now: - if dtypes differ (genuine alignment failure) the error is kept but rephrased to drop the incorrect "could not be aligned" language - if dtypes match (all-NaN column) a warning is emitted and every element is rendered with na_color, consistent with partial-NaN behaviour Co-Authored-By: Claude Sonnet 4.6 --- src/spatialdata_plot/pl/utils.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index 4c7a48d7..0fe739d2 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -1104,12 +1104,18 @@ def _set_color_source_vec( element_label = _format_element_name(element_name) location = f"table '{table_name}'" if table_name is not None else "the element" dtype_hint = _build_alignment_dtype_hint(sdata, element, color_series, table_name) - raise ValueError( - f"Column '{value_to_plot}' for element '{element_label}' contains only missing values after aligning " - f"with {location}. This usually means the instance ids/indices could not be aligned or converted, so " - "colors cannot be determined. Please ensure the table annotates the element with matching instance ids." - f"{dtype_hint}" + if dtype_hint: + raise ValueError( + f"Column '{value_to_plot}' for element '{element_label}' contains only missing values after " + f"aligning with {location}. Please ensure the table annotates the element with matching instance " + f"ids.{dtype_hint}" + ) + logger.warning( + f"Column '{value_to_plot}' for element '{element_label}' contains only NaN values; " + "rendering with na_color." ) + na_color_arr = np.full(len(color_series), na_color.get_hex_with_alpha()) + return na_color_arr, na_color_arr, False kind, processed = _infer_color_data_kind( series=color_series, From 560535be8f0890471af710820aee969ee192de5d Mon Sep 17 00:00:00 2001 From: Tim Treis Date: Fri, 24 Apr 2026 23:00:14 +0200 Subject: [PATCH 2/2] Simplify all-NaN handling: always warn, never raise Remove the dtype_hint gate that could silently swallow genuine alignment failures when _build_alignment_dtype_hint returns "" for reasons other than matching dtypes. Instead always warn and render with na_color, appending the dtype hint to the message when present. Co-Authored-By: Claude Sonnet 4.6 --- src/spatialdata_plot/pl/utils.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index 0fe739d2..1aa283e9 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -1102,17 +1102,11 @@ def _set_color_source_vec( if color_series.isna().all(): element_label = _format_element_name(element_name) - location = f"table '{table_name}'" if table_name is not None else "the element" dtype_hint = _build_alignment_dtype_hint(sdata, element, color_series, table_name) - if dtype_hint: - raise ValueError( - f"Column '{value_to_plot}' for element '{element_label}' contains only missing values after " - f"aligning with {location}. Please ensure the table annotates the element with matching instance " - f"ids.{dtype_hint}" - ) + hint_suffix = f" {dtype_hint.strip()}" if dtype_hint else "" logger.warning( f"Column '{value_to_plot}' for element '{element_label}' contains only NaN values; " - "rendering with na_color." + f"rendering with na_color.{hint_suffix}" ) na_color_arr = np.full(len(color_series), na_color.get_hex_with_alpha()) return na_color_arr, na_color_arr, False