Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7341b9

Browse filesBrowse files
authored
Merge pull request #8196 from kenmaca/pr-dash-verification-8141
Issue #8141: Dash validator allowing None values in addition to floats
2 parents f032c51 + be72573 commit f7341b9
Copy full SHA for f7341b9

File tree

Expand file treeCollapse file tree

2 files changed

+12
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-7
lines changed

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ def validate_maskedarray(v):
294294

295295

296296
class validate_nseq_float(object):
297-
def __init__(self, n=None):
297+
def __init__(self, n=None, allow_none=False):
298298
self.n = n
299+
self.allow_none = allow_none
299300

300301
def __call__(self, s):
301302
"""return a seq of n floats or raise"""
@@ -309,7 +310,10 @@ def __call__(self, s):
309310
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))
310311

311312
try:
312-
return [float(val) for val in s]
313+
return [float(val)
314+
if not self.allow_none or val is not None
315+
else val
316+
for val in s]
313317
except ValueError:
314318
raise ValueError('Could not convert all entries to floats')
315319

@@ -697,7 +701,7 @@ def validate_hatch(s):
697701
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
698702
return s
699703
validate_hatchlist = _listify_validator(validate_hatch)
700-
validate_dashlist = _listify_validator(validate_nseq_float())
704+
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))
701705

702706
_prop_validators = {
703707
'color': _listify_validator(validate_color_for_prop_cycle,
@@ -963,9 +967,10 @@ def _validate_linestyle(ls):
963967
'lines.solid_joinstyle': ['round', validate_joinstyle],
964968
'lines.dash_capstyle': ['butt', validate_capstyle],
965969
'lines.solid_capstyle': ['projecting', validate_capstyle],
966-
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float()],
967-
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6], validate_nseq_float()],
968-
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float()],
970+
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float(allow_none=True)],
971+
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6],
972+
validate_nseq_float(allow_none=True)],
973+
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float(allow_none=True)],
969974
'lines.scale_dashes': [True, validate_bool],
970975

971976
# marker props

‎lib/matplotlib/tests/test_cycles.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_cycles.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_valid_input_forms():
161161
ax.set_prop_cycle('color', np.array([[1, 0, 0],
162162
[0, 1, 0],
163163
[0, 0, 1]]))
164-
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3]])
164+
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3], [None, None]])
165165
ax.set_prop_cycle(lw=[1, 2], color=['k', 'w'], ls=['-', '--'])
166166
ax.set_prop_cycle(lw=np.array([1, 2]),
167167
color=np.array(['k', 'w']),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.