Skip to content

Commit 2718db3

Browse files
ankokumoyashijonmmease
authored andcommitted
fix to_scalar_or_list when v.ndim == 0 (#1444)
* fix to_scalar_or_list when v.ndim == 0 * add ndim=0 testcase to protect from regressions
1 parent df3ea19 commit 2718db3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

_plotly_utils/basevalidators.py

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def to_scalar_or_list(v):
5555
if isinstance(v, (list, tuple)):
5656
return [to_scalar_or_list(e) for e in v]
5757
elif np and isinstance(v, np.ndarray):
58+
if v.ndim == 0:
59+
return v.item()
5860
return [to_scalar_or_list(e) for e in v]
5961
elif pd and isinstance(v, (pd.Series, pd.Index)):
6062
return [to_scalar_or_list(e) for e in v]

_plotly_utils/tests/validators/test_dataarray_validator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def validator():
1414
# -----
1515
# ### Acceptance ###
1616
@pytest.mark.parametrize('val', [
17-
[], [1], [''], (), ('Hello, ', 'world!'), ['A', 1, 'B', 0, 'C']
17+
[], [1], [''], (), ('Hello, ', 'world!'), ['A', 1, 'B', 0, 'C'], [np.array(1), np.array(2)]
1818
])
1919
def test_validator_acceptance_simple(val, validator):
2020
coerce_val = validator.validate_coerce(val)

0 commit comments

Comments
 (0)