diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 87da535702a..94aa3ccfe2e 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -1529,7 +1529,14 @@ def _validate_rows_cols(name, n, vals): if len(vals) != n: BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals) - if [r for r in vals if not isinstance(r, int)]: + try: + import numpy as np + + int_type = (int, np.integer) + except ImportError: + int_type = (int,) + + if [r for r in vals if not isinstance(r, int_type)]: BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals) else: BaseFigure._raise_invalid_rows_cols(name=name, n=n, invalid=vals) diff --git a/packages/python/plotly/plotly/tests/test_core/test_utils/test_utils.py b/packages/python/plotly/plotly/tests/test_core/test_utils/test_utils.py index 27b77bd1d4c..d35a33d376f 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_utils/test_utils.py +++ b/packages/python/plotly/plotly/tests/test_core/test_utils/test_utils.py @@ -52,3 +52,21 @@ def test_node_generator(self): ] for i, item in enumerate(node_generator(node0)): self.assertEqual(item, expected_node_path_tuples[i]) + + +class TestNumpyIntegerBaseType(TestCase): + def test_numpy_integer_import(self): + # should generate a figure with subplots of array and not throw a ValueError + import numpy as np + import plotly.graph_objects as go + from plotly.subplots import make_subplots + + indices_rows = np.array([1], dtype=np.int) + indices_cols = np.array([1], dtype=np.int) + fig = make_subplots(rows=1, cols=1) + fig.add_trace(go.Scatter(y=[1]), row=indices_rows[0], col=indices_cols[0]) + + data_path = ("data", 0, "y") + value = get_by_path(fig, data_path) + expected_value = (1,) + self.assertEqual(value, expected_value)