Skip to content

Commit ea6cb85

Browse files
committedJun 11, 2018
Allow data_array types to be multi-dimensional numpy arrays.
This is needed for the heatmap `z` property
1 parent 9ee03f7 commit ea6cb85

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed
 

‎_plotly_utils/basevalidators.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,10 @@ def is_homogeneous_array(v):
112112
"""
113113
Return whether a value is considered to be a homogeneous array
114114
"""
115-
return ((np and isinstance(v, np.ndarray) and v.ndim == 1) or
115+
return ((np and isinstance(v, np.ndarray)) or
116116
(pd and isinstance(v, pd.Series)))
117117

118118

119-
def is_homogeneous_ndarray(v):
120-
"""
121-
Return whether a value is considered to be a homogeneous array
122-
"""
123-
return np and isinstance(v, np.ndarray)
124-
125-
126119
def is_simple_array(v):
127120
"""
128121
Return whether a value is considered to be an simple array
@@ -292,7 +285,7 @@ def __init__(self, plotly_name, parent_name, **kwargs):
292285
def description(self):
293286
return ("""\
294287
The '{plotly_name}' property is an array that may be specified as a tuple,
295-
list, one-dimensional numpy array, or pandas Series"""
288+
list, numpy array, or pandas Series"""
296289
.format(plotly_name=self.plotly_name))
297290

298291
def validate_coerce(self, v):
@@ -995,9 +988,7 @@ def validate_coerce(self, v, should_raise=True):
995988
if v is None:
996989
# Pass None through
997990
pass
998-
elif self.array_ok and (
999-
is_homogeneous_array(v) or
1000-
is_homogeneous_ndarray(v)):
991+
elif self.array_ok and is_homogeneous_array(v):
1001992

1002993
v_array = copy_to_readonly_numpy_array(v)
1003994
if (self.numbers_allowed() and

‎_plotly_utils/tests/validators/test_dataarray_validator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_validator_acceptance_simple(val, validator: DataArrayValidator):
2323

2424

2525
@pytest.mark.parametrize('val', [
26-
np.array([2, 3, 4]), pd.Series(['a', 'b', 'c'])
26+
np.array([2, 3, 4]), pd.Series(['a', 'b', 'c']), np.array([[1, 2, 3], [4, 5, 6]])
2727
])
2828
def test_validator_acceptance_homogeneous(val, validator: DataArrayValidator):
2929
coerce_val = validator.validate_coerce(val)
@@ -33,7 +33,7 @@ def test_validator_acceptance_homogeneous(val, validator: DataArrayValidator):
3333

3434
# ### Rejection ###
3535
@pytest.mark.parametrize('val', [
36-
'Hello', 23, set(), {}, np.array([[1, 2, 3], [4, 5, 6]])
36+
'Hello', 23, set(), {}
3737
])
3838
def test_rejection(val, validator: DataArrayValidator):
3939
with pytest.raises(ValueError) as validation_failure:

0 commit comments

Comments
 (0)
Please sign in to comment.