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

Skip to content

Commit 6ffd9a6

Browse files
committed
Fixes #8141
Validators for dashed linestyles now allow None as an allowed value along with floats through optional `allow_none` kwarg in validate_nseq_float. Other validators that use validate_nseq_float arent affected
1 parent 1f173dd commit 6ffd9a6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ def validate_maskedarray(v):
294294

295295

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

300300
def __call__(self, s):
301301
"""return a seq of n floats or raise"""
@@ -309,7 +309,10 @@ def __call__(self, s):
309309
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))
310310

311311
try:
312-
return [float(val) for val in s]
312+
return [float(val)
313+
if not self.allow_none and val is not None
314+
else val
315+
for val in s]
313316
except ValueError:
314317
raise ValueError('Could not convert all entries to floats')
315318

@@ -697,7 +700,7 @@ def validate_hatch(s):
697700
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
698701
return s
699702
validate_hatchlist = _listify_validator(validate_hatch)
700-
validate_dashlist = _listify_validator(validate_nseq_float())
703+
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))
701704

702705
_prop_validators = {
703706
'color': _listify_validator(validate_color_for_prop_cycle,
@@ -929,7 +932,6 @@ def _validate_linestyle(ls):
929932
raise ValueError("linestyle must be a string or " +
930933
"an even-length sequence of floats.")
931934

932-
933935
# a map from key -> value, converter
934936
defaultParams = {
935937
'backend': ['Agg', validate_backend], # agg is certainly
@@ -963,9 +965,10 @@ def _validate_linestyle(ls):
963965
'lines.solid_joinstyle': ['round', validate_joinstyle],
964966
'lines.dash_capstyle': ['butt', validate_capstyle],
965967
'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()],
968+
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float(allow_none=True)],
969+
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6],
970+
validate_nseq_float(allow_none=True)],
971+
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float(allow_none=True)],
969972
'lines.scale_dashes': [True, validate_bool],
970973

971974
# marker props

0 commit comments

Comments
 (0)