Skip to content

Commit d44b33a

Browse files
committed
Fix a bug that involves non-string columns
Solves issue #108 by converting all non-string color_groups to strings
1 parent 1377394 commit d44b33a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

dabest/plotter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
247247
color_col = plot_kwargs["color_col"]
248248
if color_col is None:
249249
color_groups = pd.unique(plot_data[xvar])
250+
color_groups = pd.Categorical([str(item) if isinstance(item, (int, float)) else item for item in color_groups])
250251
bootstraps_color_by_group = True
251252
else:
252253
if color_col not in plot_data.columns:
253254
raise KeyError("``{}`` is not a column in the data.".format(color_col))
254255
color_groups = pd.unique(plot_data[color_col])
256+
color_groups = pd.Categorical([str(item) if isinstance(item, (int, float)) else item for item in color_groups])
255257
bootstraps_color_by_group = False
256258
if show_pairs:
257259
bootstraps_color_by_group = False

nbs/API/plotter.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,13 @@
306306
" color_col = plot_kwargs[\"color_col\"]\n",
307307
" if color_col is None:\n",
308308
" color_groups = pd.unique(plot_data[xvar])\n",
309+
" color_groups = pd.Categorical([str(item) if isinstance(item, (int, float)) else item for item in color_groups])\n",
309310
" bootstraps_color_by_group = True\n",
310311
" else:\n",
311312
" if color_col not in plot_data.columns:\n",
312313
" raise KeyError(\"``{}`` is not a column in the data.\".format(color_col))\n",
313314
" color_groups = pd.unique(plot_data[color_col])\n",
315+
" color_groups = pd.Categorical([str(item) if isinstance(item, (int, float)) else item for item in color_groups])\n",
314316
" bootstraps_color_by_group = False\n",
315317
" if show_pairs:\n",
316318
" bootstraps_color_by_group = False\n",

0 commit comments

Comments
 (0)