From aae12ac520d992f06f51dd12d65f7411caf1d850 Mon Sep 17 00:00:00 2001 From: Sonja Stockhaus Date: Fri, 8 Dec 2023 15:49:56 +0100 Subject: [PATCH] add error message for when len(palette)!=len(categories) --- src/spatialdata_plot/pl/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/spatialdata_plot/pl/utils.py b/src/spatialdata_plot/pl/utils.py index 7eabe400..c3eab57f 100644 --- a/src/spatialdata_plot/pl/utils.py +++ b/src/spatialdata_plot/pl/utils.py @@ -560,6 +560,13 @@ def _get_colors_for_categorical_obs( else: palette = ["grey" for _ in range(len_cat)] logging.info("input has more than 103 categories. Uniform " "'grey' color will be used for all categories.") + else: + # raise error when user didn't provide the right number of colors in palette + if isinstance(palette, list) and len(palette) != len(categories): + raise ValueError( + f"The number of provided values in the palette ({len(palette)}) doesn't agree with the number of " + f"categories that should be colored ({categories})." + ) # otherwise, single channels turn out grey color_idx = np.linspace(0, 1, len_cat) if len_cat > 1 else [0.7]