Skip to content

Issue #8141: Dash validator allowing None values in addition to floats #8196

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 1 commit into from
Mar 8, 2017
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
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
  • Loading branch information
kenmaca committed Mar 5, 2017
commit be72573b97c29e586b37bd3dc5acf2325873a585
17 changes: 11 additions & 6 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ def validate_maskedarray(v):


class validate_nseq_float(object):
def __init__(self, n=None):
def __init__(self, n=None, allow_none=False):
self.n = n
self.allow_none = allow_none

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

try:
return [float(val) for val in s]
return [float(val)
if not self.allow_none or val is not None
else val
for val in s]
except ValueError:
raise ValueError('Could not convert all entries to floats')

Expand Down Expand Up @@ -697,7 +701,7 @@ def validate_hatch(s):
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
return s
validate_hatchlist = _listify_validator(validate_hatch)
validate_dashlist = _listify_validator(validate_nseq_float())
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))

_prop_validators = {
'color': _listify_validator(validate_color_for_prop_cycle,
Expand Down Expand Up @@ -963,9 +967,10 @@ def _validate_linestyle(ls):
'lines.solid_joinstyle': ['round', validate_joinstyle],
'lines.dash_capstyle': ['butt', validate_capstyle],
'lines.solid_capstyle': ['projecting', validate_capstyle],
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float()],
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6], validate_nseq_float()],
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float()],
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float(allow_none=True)],
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6],
validate_nseq_float(allow_none=True)],
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float(allow_none=True)],
'lines.scale_dashes': [True, validate_bool],

# marker props
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_valid_input_forms():
ax.set_prop_cycle('color', np.array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]))
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3]])
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3], [None, None]])
ax.set_prop_cycle(lw=[1, 2], color=['k', 'w'], ls=['-', '--'])
ax.set_prop_cycle(lw=np.array([1, 2]),
color=np.array(['k', 'w']),
Expand Down