Skip to content

Commit 625812f

Browse files
committed
Added new exceptions for swarmplot
1 parent 1e4145d commit 625812f

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

dabest/plot_tools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def _check_errors(
953953
if not isinstance(self.__jitter, (int, float)):
954954
raise ValueError("`jitter` must be a scalar or float.")
955955
if not isinstance(self.__palette, (str, Iterable)):
956-
raise ValueError("`palette` must be either a string or an Iterable.")
956+
raise ValueError("`palette` must be either a string indicating a color name or an Iterable.")
957957
if self.__hue is not None and not isinstance(self.__hue, str):
958958
raise ValueError("`hue` must be either a string or None.")
959959
if self.__order is not None and not isinstance(self.__order, Iterable):
@@ -978,15 +978,23 @@ def _check_errors(
978978
group_i, self.__x
979979
)
980980
raise IndexError(err)
981+
982+
if isinstance(self.__palette, str) and self.__palette.strip() == "":
983+
err = "`palette` cannot be an empty string. It must be either a string indicating a color name or an Iterable."
984+
raise ValueError(err)
981985
if isinstance(self.__palette, dict):
982-
for group_i in self.__palette.keys():
986+
# TODO: to add detection of when dict length is less than size of unique_items
987+
for group_i, color_i in self.__palette.items():
983988
if group_i not in pd.unique(data[color_col]):
984989
err = (
985990
"{0} in `palette` is not in the '{1}' column of `data`.".format(
986991
group_i, color_col
987992
)
988993
)
989994
raise IndexError(err)
995+
if isinstance(color_i, str) and color_i.strip() == "":
996+
err = "The color mapping for {0} in `palette` is an empty string. It must contain a color name.".format(group_i)
997+
raise ValueError(err)
990998

991999
if side.lower() not in ["center", "right", "left"]:
9921000
raise ValueError(

nbs/API/plot_tools.ipynb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@
10161016
" if not isinstance(self.__jitter, (int, float)):\n",
10171017
" raise ValueError(\"`jitter` must be a scalar or float.\")\n",
10181018
" if not isinstance(self.__palette, (str, Iterable)):\n",
1019-
" raise ValueError(\"`palette` must be either a string or an Iterable.\")\n",
1019+
" raise ValueError(\"`palette` must be either a string indicating a color name or an Iterable.\")\n",
10201020
" if self.__hue is not None and not isinstance(self.__hue, str):\n",
10211021
" raise ValueError(\"`hue` must be either a string or None.\")\n",
10221022
" if self.__order is not None and not isinstance(self.__order, Iterable):\n",
@@ -1041,15 +1041,23 @@
10411041
" group_i, self.__x\n",
10421042
" )\n",
10431043
" raise IndexError(err)\n",
1044+
"\n",
1045+
" if isinstance(self.__palette, str) and self.__palette.strip() == \"\":\n",
1046+
" err = \"`palette` cannot be an empty string. It must be either a string indicating a color name or an Iterable.\"\n",
1047+
" raise ValueError(err)\n",
10441048
" if isinstance(self.__palette, dict):\n",
1045-
" for group_i in self.__palette.keys():\n",
1049+
" # TODO: to add detection of when dict length is less than size of unique_items\n",
1050+
" for group_i, color_i in self.__palette.items():\n",
10461051
" if group_i not in pd.unique(data[color_col]):\n",
10471052
" err = (\n",
10481053
" \"{0} in `palette` is not in the '{1}' column of `data`.\".format(\n",
10491054
" group_i, color_col\n",
10501055
" )\n",
10511056
" )\n",
10521057
" raise IndexError(err)\n",
1058+
" if isinstance(color_i, str) and color_i.strip() == \"\":\n",
1059+
" err = \"The color mapping for {0} in `palette` is an empty string. It must contain a color name.\".format(group_i)\n",
1060+
" raise ValueError(err) \n",
10531061
"\n",
10541062
" if side.lower() not in [\"center\", \"right\", \"left\"]:\n",
10551063
" raise ValueError(\n",

0 commit comments

Comments
 (0)