Skip to content

Commit 03187b0

Browse files
committed
added error message if custom_palette list shorter than the number of groups
1 parent faf284d commit 03187b0

3 files changed

Lines changed: 58 additions & 27 deletions

File tree

dabest/misc_tools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,18 @@ def get_color_palette(
578578
k: custom_pal[k] for k in all_plot_groups if k in color_groups
579579
}
580580
else:
581-
raise ValueError("The `custom_palette` dictionary is not supported when `color_col` is None.")
581+
raise ValueError("The `custom_palette` dictionary is not supported when `color_col` is not None.")
582582

583583
names = groups_in_palette.keys()
584584
unsat_colors = groups_in_palette.values()
585585

586586
elif isinstance(custom_pal, list):
587-
unsat_colors = custom_pal[0:n_groups]
587+
if len(custom_pal) < n_groups:
588+
err1 = "The specified `custom_palette` has fewer colors than the number of groups."
589+
err2 = " Please specify a custom palette with at least {} colors.".format(n_groups)
590+
raise ValueError(err1 + err2)
591+
else:
592+
unsat_colors = custom_pal[0:n_groups]
588593

589594
elif isinstance(custom_pal, str):
590595
# check it is in the list of matplotlib palettes.

nbs/API/misc_tools.ipynb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,18 @@
631631
" k: custom_pal[k] for k in all_plot_groups if k in color_groups\n",
632632
" }\n",
633633
" else:\n",
634-
" raise ValueError(\"The `custom_palette` dictionary is not supported when `color_col` is None.\")\n",
634+
" raise ValueError(\"The `custom_palette` dictionary is not supported when `color_col` is not None.\")\n",
635635
"\n",
636636
" names = groups_in_palette.keys()\n",
637637
" unsat_colors = groups_in_palette.values()\n",
638638
"\n",
639639
" elif isinstance(custom_pal, list):\n",
640-
" unsat_colors = custom_pal[0:n_groups]\n",
640+
" if len(custom_pal) < n_groups:\n",
641+
" err1 = \"The specified `custom_palette` has fewer colors than the number of groups.\"\n",
642+
" err2 = \" Please specify a custom palette with at least {} colors.\".format(n_groups)\n",
643+
" raise ValueError(err1 + err2)\n",
644+
" else:\n",
645+
" unsat_colors = custom_pal[0:n_groups]\n",
641646
"\n",
642647
" elif isinstance(custom_pal, str):\n",
643648
" # check it is in the list of matplotlib palettes.\n",

0 commit comments

Comments
 (0)