Skip to content

Fix incorrect validation error for animate args info array #1267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions _plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,32 +1808,29 @@ def validate_coerce(self, v):

is_v_2d = v and is_array(v[0])

if is_v_2d:
if self.dimensions == 1:
self.raise_invalid_val(orig_v)
else: # self.dimensions is '1-2' or 2
if is_array(self.items):
# e.g. 2D list as parcoords.dimensions.constraintrange
# check that all items are there for each nested element
for i, row in enumerate(v):
# Check row length
if not is_array(row) or len(row) != len(self.items):
self.raise_invalid_val(orig_v[i], [i])

for j, validator in enumerate(self.item_validators):
row[j] = self.validate_element_with_indexed_name(
v[i][j], validator, [i, j])
else:
# e.g. 2D list as layout.grid.subplots
# check that all elements match individual validator
validator = self.item_validators[0]
for i, row in enumerate(v):
if not is_array(row):
self.raise_invalid_val(orig_v[i], [i])

for j, el in enumerate(row):
row[j] = self.validate_element_with_indexed_name(
el, validator, [i, j])
if is_v_2d and self.dimensions in ('1-2', 2):
if is_array(self.items):
# e.g. 2D list as parcoords.dimensions.constraintrange
# check that all items are there for each nested element
for i, row in enumerate(v):
# Check row length
if not is_array(row) or len(row) != len(self.items):
self.raise_invalid_val(orig_v[i], [i])

for j, validator in enumerate(self.item_validators):
row[j] = self.validate_element_with_indexed_name(
v[i][j], validator, [i, j])
else:
# e.g. 2D list as layout.grid.subplots
# check that all elements match individual validator
validator = self.item_validators[0]
for i, row in enumerate(v):
if not is_array(row):
self.raise_invalid_val(orig_v[i], [i])

for j, el in enumerate(row):
row[j] = self.validate_element_with_indexed_name(
el, validator, [i, j])
elif v and self.dimensions == 2:
# e.g. 1D list passed as layout.grid.subplots
self.raise_invalid_val(orig_v[0], [0])
Expand Down
29 changes: 29 additions & 0 deletions _plotly_utils/tests/validators/test_infoarray_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def validator_number3_free():
{'valType': 'number', 'min': 0, 'max': 1}], free_length=True)


@pytest.fixture()
def validator_any3_free():
return InfoArrayValidator('prop', 'parent', items=[
{'valType': 'any'},
{'valType': 'any'},
{'valType': 'any'}], free_length=True)


@pytest.fixture()
def validator_number2_2d():
return InfoArrayValidator('prop', 'parent', items=[
Expand Down Expand Up @@ -219,6 +227,27 @@ def test_validator_rejection_number3_free_element_value(val, first_invalid_ind,
first_invalid_ind=first_invalid_ind)) in str(validation_failure.value)


# Any3 Tests (free_length=True)
# --------------------------------
# ### Acceptance ###
@pytest.mark.parametrize('val', [
[1, 0, 'Hello'],
(False, 0.99),
np.array([0.1, 0.99]),
[0], [],
[['a', 'list']],
[['a', 'list'], 0],
[0, ['a', 'list'], 1],
])
def test_validator_acceptance_any3_free(val, validator_any3_free):
coerce_val = validator_any3_free.validate_coerce(val)
assert coerce_val == list(val)

# Compute expected
expected = tuple(tuple(el) if isinstance(el, list) else el for el in val)
assert validator_any3_free.present(coerce_val) == expected


# Number2 2D
# ----------
# ### Acceptance ###
Expand Down