Skip to content

Commit 5305ec2

Browse files
committed
Re-implementing PR#109 from Marin_Manuel
- Also added Marin Manuel to contributor list
1 parent 862804f commit 5305ec2

5 files changed

Lines changed: 12 additions & 32 deletions

File tree

dabest/_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def __init__(self, data, idx, x, y, paired, id_col, ci,
175175

176176

177177
# Determine the kind of estimation plot we need to produce.
178-
if all([isinstance(i, str) for i in idx]):
178+
if all([isinstance(i, (str, int, float)) for i in idx]):
179179
# flatten out idx.
180180
all_plot_groups = pd.unique([t for t in idx]).tolist()
181181
if len(idx) > len(all_plot_groups):

dabest/plotter.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -402,35 +402,24 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
402402
# Plot the raw data as a slopegraph.
403403
# Pivot the long (melted) data.
404404
if color_col is None:
405-
pivot_values = yvar
405+
pivot_values = [yvar]
406406
else:
407407
pivot_values = [yvar, color_col]
408408
pivoted_plot_data = pd.pivot(data=plot_data, index=dabest_obj.id_col,
409409
columns=xvar, values=pivot_values)
410410
x_start = 0
411411
for ii, current_tuple in enumerate(temp_idx):
412-
if len(temp_idx) > 1:
413-
# Select only the data for the current tuple.
414-
if color_col is None:
415-
current_pair = pivoted_plot_data.reindex(columns=current_tuple)
416-
else:
417-
current_pair = pivoted_plot_data[yvar].reindex(columns=current_tuple)
418-
else:
419-
if color_col is None:
420-
current_pair = pivoted_plot_data
421-
else:
422-
current_pair = pivoted_plot_data[yvar]
412+
current_pair = pivoted_plot_data.loc[:, pd.MultiIndex.from_product([pivot_values, current_tuple])].dropna()
423413
grp_count = len(current_tuple)
424414
# Iterate through the data for the current tuple.
425415
for ID, observation in current_pair.iterrows():
426416
x_points = [t for t in range(x_start, x_start + grp_count)]
427-
y_points = observation.tolist()
417+
y_points = observation[yvar].tolist()
428418

429419
if color_col is None:
430420
slopegraph_kwargs['color'] = ytick_color
431421
else:
432-
color_key = pivoted_plot_data[color_col,
433-
current_tuple[0]].loc[ID]
422+
color_key = observation[color_col][0]
434423
if isinstance(color_key, str) == True:
435424
slopegraph_kwargs['color'] = plot_palette_raw[color_key]
436425
slopegraph_kwargs['label'] = color_key

nbs/02-about.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"\n",
3939
"- Adam Nekimken ([@anekimken](https://github.com/anekimken)) with [PR #73](https://github.com/ACCLAB/DABEST-python/pull/73): Implement inset axes so estimation plots can be plotted on a pre-determined :py:mod:`matplotlib` :py:class:`Axes` object.\n",
4040
"\n",
41+
"- Marin Manuel ([@MarinManuel](https://github.com/MarinManuel)) with [PR #109](https://github.com/ACCLAB/DABEST-python/pull/109): Fixed bug preventing non-string columns from being used.\n",
42+
"\n",
4143
"\n",
4244
"\n",
4345
"## Typography\n",

nbs/API/class.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
"\n",
245245
"\n",
246246
" # Determine the kind of estimation plot we need to produce.\n",
247-
" if all([isinstance(i, str) for i in idx]):\n",
247+
" if all([isinstance(i, (str, int, float)) for i in idx]):\n",
248248
" # flatten out idx.\n",
249249
" all_plot_groups = pd.unique([t for t in idx]).tolist()\n",
250250
" if len(idx) > len(all_plot_groups):\n",

nbs/API/plotter.ipynb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -452,35 +452,24 @@
452452
" # Plot the raw data as a slopegraph.\n",
453453
" # Pivot the long (melted) data.\n",
454454
" if color_col is None:\n",
455-
" pivot_values = yvar\n",
455+
" pivot_values = [yvar]\n",
456456
" else:\n",
457457
" pivot_values = [yvar, color_col]\n",
458458
" pivoted_plot_data = pd.pivot(data=plot_data, index=dabest_obj.id_col,\n",
459459
" columns=xvar, values=pivot_values)\n",
460460
" x_start = 0\n",
461461
" for ii, current_tuple in enumerate(temp_idx):\n",
462-
" if len(temp_idx) > 1:\n",
463-
" # Select only the data for the current tuple.\n",
464-
" if color_col is None:\n",
465-
" current_pair = pivoted_plot_data.reindex(columns=current_tuple)\n",
466-
" else:\n",
467-
" current_pair = pivoted_plot_data[yvar].reindex(columns=current_tuple)\n",
468-
" else:\n",
469-
" if color_col is None:\n",
470-
" current_pair = pivoted_plot_data\n",
471-
" else:\n",
472-
" current_pair = pivoted_plot_data[yvar]\n",
462+
" current_pair = pivoted_plot_data.loc[:, pd.MultiIndex.from_product([pivot_values, current_tuple])].dropna()\n",
473463
" grp_count = len(current_tuple)\n",
474464
" # Iterate through the data for the current tuple.\n",
475465
" for ID, observation in current_pair.iterrows():\n",
476466
" x_points = [t for t in range(x_start, x_start + grp_count)]\n",
477-
" y_points = observation.tolist()\n",
467+
" y_points = observation[yvar].tolist()\n",
478468
"\n",
479469
" if color_col is None:\n",
480470
" slopegraph_kwargs['color'] = ytick_color\n",
481471
" else:\n",
482-
" color_key = pivoted_plot_data[color_col,\n",
483-
" current_tuple[0]].loc[ID]\n",
472+
" color_key = observation[color_col][0]\n",
484473
" if isinstance(color_key, str) == True:\n",
485474
" slopegraph_kwargs['color'] = plot_palette_raw[color_key]\n",
486475
" slopegraph_kwargs['label'] = color_key\n",

0 commit comments

Comments
 (0)