Skip to content

Commit d192b79

Browse files
timtreisclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 9afec7e commit d192b79

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/spatialdata_plot/pl/utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,12 +1104,18 @@ def _set_color_source_vec(
11041104
element_label = _format_element_name(element_name)
11051105
location = f"table '{table_name}'" if table_name is not None else "the element"
11061106
dtype_hint = _build_alignment_dtype_hint(sdata, element, color_series, table_name)
1107-
raise ValueError(
1108-
f"Column '{value_to_plot}' for element '{element_label}' contains only missing values after aligning "
1109-
f"with {location}. This usually means the instance ids/indices could not be aligned or converted, so "
1110-
"colors cannot be determined. Please ensure the table annotates the element with matching instance ids."
1111-
f"{dtype_hint}"
1107+
if dtype_hint:
1108+
raise ValueError(
1109+
f"Column '{value_to_plot}' for element '{element_label}' contains only missing values after "
1110+
f"aligning with {location}. Please ensure the table annotates the element with matching instance "
1111+
f"ids.{dtype_hint}"
1112+
)
1113+
logger.warning(
1114+
f"Column '{value_to_plot}' for element '{element_label}' contains only NaN values; "
1115+
"rendering with na_color."
11121116
)
1117+
na_color_arr = np.full(len(color_series), na_color.get_hex_with_alpha())
1118+
return na_color_arr, na_color_arr, False
11131119

11141120
kind, processed = _infer_color_data_kind(
11151121
series=color_series,

0 commit comments

Comments
 (0)