Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 267c187

Browse filesBrowse files
authored
bug_2931: resolving numpy integer check and adding test (plotly#2451)
1 parent 03d161c commit 267c187
Copy full SHA for 267c187

File tree

Expand file treeCollapse file tree

2 files changed

+26
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-1
lines changed

‎packages/python/plotly/plotly/basedatatypes.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/basedatatypes.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,14 @@ def _validate_rows_cols(name, n, vals):
15601560
if len(vals) != n:
15611561
BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals)
15621562

1563-
if [r for r in vals if not isinstance(r, int)]:
1563+
try:
1564+
import numpy as np
1565+
1566+
int_type = (int, np.integer)
1567+
except ImportError:
1568+
int_type = (int,)
1569+
1570+
if [r for r in vals if not isinstance(r, int_type)]:
15641571
BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals)
15651572
else:
15661573
BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals)

‎packages/python/plotly/plotly/tests/test_core/test_utils/test_utils.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/tests/test_core/test_utils/test_utils.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ def test_node_generator(self):
5252
]
5353
for i, item in enumerate(node_generator(node0)):
5454
self.assertEqual(item, expected_node_path_tuples[i])
55+
56+
57+
class TestNumpyIntegerBaseType(TestCase):
58+
def test_numpy_integer_import(self):
59+
# should generate a figure with subplots of array and not throw a ValueError
60+
import numpy as np
61+
import plotly.graph_objects as go
62+
from plotly.subplots import make_subplots
63+
64+
indices_rows = np.array([1], dtype=np.int)
65+
indices_cols = np.array([1], dtype=np.int)
66+
fig = make_subplots(rows=1, cols=1)
67+
fig.add_trace(go.Scatter(y=[1]), row=indices_rows[0], col=indices_cols[0])
68+
69+
data_path = ("data", 0, "y")
70+
value = get_by_path(fig, data_path)
71+
expected_value = (1,)
72+
self.assertEqual(value, expected_value)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.