Skip to content

Commit a048ef2

Browse files
committed
fix(bar): handle empty significance plot without error
When statistical testing yields no significant results, the `comparisons` list is empty, which previously caused the function to crash. A conditional check has been added to exit the function early in such cases, as no plotting is needed.
1 parent 98eb400 commit a048ef2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/plotfig/bar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _stars(pval, i, y, color, fontsize):
166166
),
167167
)
168168
_stars(pval, (i + j) / 2, y + star_offset, color, fontsize)
169-
else:
169+
elif len(comparisons[0]) == 2:
170170
for i, pval in comparisons:
171171
y = y_base + interval
172172
_stars(pval, i, y + star_offset, color, fontsize)
@@ -202,6 +202,8 @@ def statistics(
202202
_, p = perform_stat_test(data1=data[i], popmean=popmean, method=test_method)
203203
if p <= 0.05:
204204
comparisons.append((i, p))
205+
if not comparisons:
206+
return
205207

206208
y_max = ax.get_ylim()[1]
207209
interval = (y_max - np.max(all_values)) / (len(comparisons) + 1)

0 commit comments

Comments
 (0)