Skip to content

Fix "The truth value of an array with more than one element is ambiguous" #1685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/python/plotly/plotly/subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,13 @@ def _checks(item, defaults):

# ### vertical_spacing ###
if vertical_spacing is None:
if subplot_titles:
if subplot_titles is not None:
vertical_spacing = 0.5 / rows
else:
vertical_spacing = 0.3 / rows

# ### subplot titles ###
if not subplot_titles:
if subplot_titles is None:
subplot_titles = [""] * rows * cols

# ### column_widths ###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,24 @@ def test_subplot_titles_insets(self):
)
self.assertEqual(fig, expected)

def test_subplot_titles_array(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this test is testing subplot titles as a tuple. If that's what you're intending, lets name this test_subplot_titles_tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All current tests are using tuples as subplot_titles argument. I thought it would be a good idea to add a test which checks if it works the same with python array.

# Pass python array
expected = tls.make_subplots(
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=("", "Inset")
)
fig = tls.make_subplots(
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=["", "Inset"]
)
self.assertEqual(fig, expected)

def test_subplot_titles_empty(self):
# Pass empty array
expected = tls.make_subplots(insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}])
fig = tls.make_subplots(
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=[]
)
self.assertEqual(fig, expected)

def test_large_columns_no_errors(self):
"""
Test that creating subplots with a large number of columns, and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np

from unittest import TestCase

import plotly.tools as tls


class TestMakeSubplots(TestCase):
def test_subplot_titles_numpy_array(self):
# Pass numpy array
expected = tls.make_subplots(
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=("", "Inset")
)
fig = tls.make_subplots(
insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}],
subplot_titles=np.array(["", "Inset"]),
)
self.assertEqual(fig, expected)