Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 058f6b1

Browse files
NelleVQuLogic
authored andcommitted
Merge pull request #8196 from kenmaca/pr-dash-verification-8141
Issue #8141: Dash validator allowing None values in addition to floats
1 parent 26ffec5 commit 058f6b1

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ def validate_maskedarray(v):
298298

299299

300300
class validate_nseq_float(object):
301-
def __init__(self, n=None):
301+
def __init__(self, n=None, allow_none=False):
302302
self.n = n
303+
self.allow_none = allow_none
303304

304305
def __call__(self, s):
305306
"""return a seq of n floats or raise"""
@@ -313,7 +314,10 @@ def __call__(self, s):
313314
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))
314315

315316
try:
316-
return [float(val) for val in s]
317+
return [float(val)
318+
if not self.allow_none or val is not None
319+
else val
320+
for val in s]
317321
except ValueError:
318322
raise ValueError('Could not convert all entries to floats')
319323

@@ -695,7 +699,7 @@ def validate_hatch(s):
695699
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
696700
return s
697701
validate_hatchlist = _listify_validator(validate_hatch)
698-
validate_dashlist = _listify_validator(validate_nseq_float())
702+
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))
699703

700704
_prop_validators = {
701705
'color': _listify_validator(validate_color_for_prop_cycle,
@@ -928,9 +932,10 @@ def validate_animation_writer_path(p):
928932
'lines.solid_joinstyle': ['round', validate_joinstyle],
929933
'lines.dash_capstyle': ['butt', validate_capstyle],
930934
'lines.solid_capstyle': ['projecting', validate_capstyle],
931-
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float()],
932-
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6], validate_nseq_float()],
933-
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float()],
935+
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float(allow_none=True)],
936+
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6],
937+
validate_nseq_float(allow_none=True)],
938+
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float(allow_none=True)],
934939
'lines.scale_dashes': [True, validate_bool],
935940

936941
# marker props

lib/matplotlib/tests/test_cycles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_valid_input_forms():
162162
ax.set_prop_cycle('color', np.array([[1, 0, 0],
163163
[0, 1, 0],
164164
[0, 0, 1]]))
165-
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3]])
165+
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3], [None, None]])
166166
ax.set_prop_cycle(lw=[1, 2], color=['k', 'w'], ls=['-', '--'])
167167
ax.set_prop_cycle(lw=np.array([1, 2]),
168168
color=np.array(['k', 'w']),

0 commit comments

Comments
 (0)