Skip to content

add error message for when len(palette)!=len(categories) #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down