From e438afec35e293ec317282fc5d0d91f4c8a64923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B5=83?= Date: Fri, 1 Mar 2019 19:42:18 +0900 Subject: [PATCH 1/2] fix to_scalar_or_list when v.ndim == 0 --- _plotly_utils/basevalidators.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index ff10a491f45..db6d4e4d4a4 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -55,6 +55,8 @@ def to_scalar_or_list(v): if isinstance(v, (list, tuple)): return [to_scalar_or_list(e) for e in v] elif np and isinstance(v, np.ndarray): + if v.ndim == 0: + return v.item() return [to_scalar_or_list(e) for e in v] elif pd and isinstance(v, (pd.Series, pd.Index)): return [to_scalar_or_list(e) for e in v] From a76a98bb83850d089e03aa1039af9d506168bb42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B5=83?= Date: Tue, 5 Mar 2019 15:30:22 +0900 Subject: [PATCH 2/2] add ndim=0 testcase to protect from regressions --- _plotly_utils/tests/validators/test_dataarray_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_plotly_utils/tests/validators/test_dataarray_validator.py b/_plotly_utils/tests/validators/test_dataarray_validator.py index b3bc03a13f0..c366e229ea5 100644 --- a/_plotly_utils/tests/validators/test_dataarray_validator.py +++ b/_plotly_utils/tests/validators/test_dataarray_validator.py @@ -14,7 +14,7 @@ def validator(): # ----- # ### Acceptance ### @pytest.mark.parametrize('val', [ - [], [1], [''], (), ('Hello, ', 'world!'), ['A', 1, 'B', 0, 'C'] + [], [1], [''], (), ('Hello, ', 'world!'), ['A', 1, 'B', 0, 'C'], [np.array(1), np.array(2)] ]) def test_validator_acceptance_simple(val, validator): coerce_val = validator.validate_coerce(val)