Skip to content

Commit 9bb23e6

Browse files
Sonja-StockhausSonja Stockhaus
and
Sonja Stockhaus
authored
add error message for when len(palette)!=len(categories) (#197)
Co-authored-by: Sonja Stockhaus <[email protected]>
1 parent f7fac79 commit 9bb23e6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/spatialdata_plot/pl/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,13 @@ def _get_colors_for_categorical_obs(
560560
else:
561561
palette = ["grey" for _ in range(len_cat)]
562562
logging.info("input has more than 103 categories. Uniform " "'grey' color will be used for all categories.")
563+
else:
564+
# raise error when user didn't provide the right number of colors in palette
565+
if isinstance(palette, list) and len(palette) != len(categories):
566+
raise ValueError(
567+
f"The number of provided values in the palette ({len(palette)}) doesn't agree with the number of "
568+
f"categories that should be colored ({categories})."
569+
)
563570

564571
# otherwise, single channels turn out grey
565572
color_idx = np.linspace(0, 1, len_cat) if len_cat > 1 else [0.7]

0 commit comments

Comments
 (0)