Skip to content

Commit bd8d374

Browse files
MrQubojonmmease
authored andcommitted
Fix "The truth value of an array with more than one element is ambiguous" (#1685)
* Fix "The truth value of an array with more than one element is ambiguous". Fixes "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
1 parent 1b501d4 commit bd8d374

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

packages/python/plotly/plotly/subplots.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,13 @@ def _checks(item, defaults):
511511

512512
# ### vertical_spacing ###
513513
if vertical_spacing is None:
514-
if subplot_titles:
514+
if subplot_titles is not None:
515515
vertical_spacing = 0.5 / rows
516516
else:
517517
vertical_spacing = 0.3 / rows
518518

519519
# ### subplot titles ###
520-
if not subplot_titles:
520+
if subplot_titles is None:
521521
subplot_titles = [""] * rows * cols
522522

523523
# ### column_widths ###

packages/python/plotly/plotly/tests/test_core/test_subplots/test_make_subplots.py

+18
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,24 @@ def test_subplot_titles_insets(self):
15421542
)
15431543
self.assertEqual(fig, expected)
15441544

1545+
def test_subplot_titles_array(self):
1546+
# Pass python array
1547+
expected = tls.make_subplots(
1548+
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=("", "Inset")
1549+
)
1550+
fig = tls.make_subplots(
1551+
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=["", "Inset"]
1552+
)
1553+
self.assertEqual(fig, expected)
1554+
1555+
def test_subplot_titles_empty(self):
1556+
# Pass empty array
1557+
expected = tls.make_subplots(insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}])
1558+
fig = tls.make_subplots(
1559+
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=[]
1560+
)
1561+
self.assertEqual(fig, expected)
1562+
15451563
def test_large_columns_no_errors(self):
15461564
"""
15471565
Test that creating subplots with a large number of columns, and
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import numpy as np
2+
3+
from unittest import TestCase
4+
5+
import plotly.tools as tls
6+
7+
8+
class TestMakeSubplots(TestCase):
9+
def test_subplot_titles_numpy_array(self):
10+
# Pass numpy array
11+
expected = tls.make_subplots(
12+
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=("", "Inset")
13+
)
14+
fig = tls.make_subplots(
15+
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}],
16+
subplot_titles=np.array(["", "Inset"]),
17+
)
18+
self.assertEqual(fig, expected)

0 commit comments

Comments
 (0)