Skip to content

Commit 69ec52a

Browse files
authored
Don't convert None to 'None' string in a non-strict string array (#1249)
Leave value as None so that plotly.js sees it as null
1 parent 5305f74 commit 69ec52a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Diff for: _plotly_utils/basevalidators.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,10 @@ def validate_coerce(self, v):
938938

939939
elif is_simple_array(v):
940940
if not self.strict:
941-
v = [str(e) for e in v]
941+
# Convert all elements other than None to strings
942+
# Leave None as is, Plotly.js will decide how to handle
943+
# these null values.
944+
v = [str(e) if e is not None else None for e in v]
942945

943946
# Check no_blank
944947
if self.no_blank:

Diff for: _plotly_utils/tests/validators/test_string_validator.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ def validator_strict():
2727

2828
@pytest.fixture
2929
def validator_aok():
30-
return StringValidator('prop', 'parent', array_ok=True, strict=True)
30+
return StringValidator('prop', 'parent', array_ok=True, strict=False)
31+
3132

33+
@pytest.fixture
34+
def validator_aok_strict():
35+
return StringValidator('prop', 'parent', array_ok=True, strict=True)
3236

3337
@pytest.fixture
3438
def validator_aok_values():
@@ -127,7 +131,8 @@ def test_acceptance_aok_scalars(val, validator_aok):
127131
['foo',
128132
['foo'],
129133
np.array(['BAR', ''], dtype='object'),
130-
['baz', 'baz', 'baz']])
134+
['baz', 'baz', 'baz'],
135+
['foo', None, 'bar']])
131136
def test_acceptance_aok_list(val, validator_aok):
132137
coerce_val = validator_aok.validate_coerce(val)
133138
if isinstance(val, np.ndarray):
@@ -143,16 +148,19 @@ def test_acceptance_aok_list(val, validator_aok):
143148
# ### Rejection by type ###
144149
@pytest.mark.parametrize('val',
145150
[['foo', ()], ['foo', 3, 4], [3, 2, 1]])
146-
def test_rejection_aok(val, validator_aok):
151+
def test_rejection_aok(val, validator_aok_strict):
147152
with pytest.raises(ValueError) as validation_failure:
148-
validator_aok.validate_coerce(val)
153+
validator_aok_strict.validate_coerce(val)
149154

150155
assert 'Invalid element(s)' in str(validation_failure.value)
151156

152157

153158
# ### Rejection by value ###
154159
@pytest.mark.parametrize('val',
155-
[['foo', 'bar'], ['3', '4'], ['BAR', 'BAR', 'hello!']])
160+
[['foo', 'bar'],
161+
['3', '4'],
162+
['BAR', 'BAR', 'hello!'],
163+
['foo', None]])
156164
def test_rejection_aok_values(val, validator_aok_values):
157165
with pytest.raises(ValueError) as validation_failure:
158166
validator_aok_values.validate_coerce(val)

0 commit comments

Comments
 (0)