From 061061b564de2f93ef2c870c0d99bd51259ca963 Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Tue, 7 Feb 2017 16:45:19 +0100 Subject: [PATCH 01/15] extend 'grid.linestyle' valid types to on-off ink sequences --- lib/matplotlib/rcsetup.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a5a248c156bd..0e860740a55d 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -889,6 +889,26 @@ def validate_animation_writer_path(p): return p +def validate_grid_linestyle(ls): + # Named line style, like u'--' or u'solid' + if isinstance(ls, six.text_type): + return ls + # Sequence of even length of on and off ink in points. + # Offset is set to None. + try: + if len(ls) % 2 != 0: + # Expecting a sequence of even length + raise ValueError + return (None, validate_nseq_float()(ls)) + except (ValueError, TypeError): + # TypeError can be raised by wrong types passed to float() + # (called inside the instance of validate_nseq_float). + pass + + raise ValueError("'grid.linestyle' must be a string or " + + "a even-length sequence of floats.") + + # a map from key -> value, converter defaultParams = { 'backend': ['Agg', validate_backend], # agg is certainly @@ -1215,7 +1235,7 @@ def validate_animation_writer_path(p): 'ytick.direction': ['out', six.text_type], # direction of yticks 'grid.color': ['#b0b0b0', validate_color], # grid color - 'grid.linestyle': ['-', six.text_type], # solid + 'grid.linestyle': ['-', validate_grid_linestyle], # solid 'grid.linewidth': [0.8, validate_float], # in points 'grid.alpha': [1.0, validate_float], From 5be29b5015c110bc8bbe57ad152d7d85c64198a1 Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Tue, 7 Feb 2017 16:46:27 +0100 Subject: [PATCH 02/15] extend 'add test for the new function 'validate_grid_linestyle' --- lib/matplotlib/tests/test_rcparams.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index b376170ac31c..1b622e120b70 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -29,7 +29,8 @@ validate_nseq_float, validate_cycler, validate_hatch, - validate_hist_bins) + validate_hist_bins, + validate_grid_linestyle) mpl.rc('text', usetex=False) @@ -333,6 +334,21 @@ def generate_validator_testcases(valid): ), 'fail': (('aardvark', ValueError), ) + }, + {'validator': validate_grid_linestyle, + 'success': (('--', '--'), + ('dotted', 'dotted'), + ('aardvark', 'aardvark'), + (['1.23', '4.56'], (None, [1.23, 4.56])), + ([1.23, 456], (None, [1.23, 456.0])), + ([1, 2, 3, 4], (None, [1.0, 2.0, 3.0, 4.0])), + ), + 'fail': (((None, [1, 2]), ValueError), + ((0, [1, 2]), ValueError), + ((-1, [1, 2]), ValueError), + ([1, 2, 3], ValueError), + (1.23, ValueError) + ) } ) From 25efd07d7f6c766171dab01f5da5370cd8c18e35 Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Wed, 8 Feb 2017 13:29:27 +0100 Subject: [PATCH 03/15] fix a small typo --- lib/matplotlib/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 0e860740a55d..6d2f319c749e 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -906,7 +906,7 @@ def validate_grid_linestyle(ls): pass raise ValueError("'grid.linestyle' must be a string or " + - "a even-length sequence of floats.") + "an even-length sequence of floats.") # a map from key -> value, converter From 5cb183c6ff7d67b7fda81b7cddf34b5dc9f7a0bf Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Thu, 9 Feb 2017 19:11:47 +0100 Subject: [PATCH 04/15] Relax validation for all ls-related rcParams but contour.negative_linestyle --- lib/matplotlib/rcsetup.py | 23 ++++++++++++----------- lib/matplotlib/tests/test_rcparams.py | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 6d2f319c749e..e2d317fa8363 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -889,11 +889,12 @@ def validate_animation_writer_path(p): return p -def validate_grid_linestyle(ls): +def validate_linestyle(ls): # Named line style, like u'--' or u'solid' if isinstance(ls, six.text_type): return ls - # Sequence of even length of on and off ink in points. + + # Sequence *of even length* of on and off ink (in points). # Offset is set to None. try: if len(ls) % 2 != 0: @@ -905,7 +906,7 @@ def validate_grid_linestyle(ls): # (called inside the instance of validate_nseq_float). pass - raise ValueError("'grid.linestyle' must be a string or " + + raise ValueError("linestyle must be a string or " + "an even-length sequence of floats.") @@ -932,7 +933,7 @@ def validate_grid_linestyle(ls): # line props 'lines.linewidth': [1.5, validate_float], # line width in points - 'lines.linestyle': ['-', six.text_type], # solid line + 'lines.linestyle': ['-', validate_linestyle], # solid line 'lines.color': ['C0', validate_color], # first color in color cycle 'lines.marker': ['None', six.text_type], # marker name 'lines.markeredgewidth': [1.0, validate_float], @@ -981,31 +982,31 @@ def validate_grid_linestyle(ls): 'boxplot.flierprops.markerfacecolor': ['none', validate_color_or_auto], 'boxplot.flierprops.markeredgecolor': ['k', validate_color], 'boxplot.flierprops.markersize': [6, validate_float], - 'boxplot.flierprops.linestyle': ['none', six.text_type], + 'boxplot.flierprops.linestyle': ['none', validate_linestyle], 'boxplot.flierprops.linewidth': [1.0, validate_float], 'boxplot.boxprops.color': ['k', validate_color], 'boxplot.boxprops.linewidth': [1.0, validate_float], - 'boxplot.boxprops.linestyle': ['-', six.text_type], + 'boxplot.boxprops.linestyle': ['-', validate_linestyle], 'boxplot.whiskerprops.color': ['k', validate_color], 'boxplot.whiskerprops.linewidth': [1.0, validate_float], - 'boxplot.whiskerprops.linestyle': ['-', six.text_type], + 'boxplot.whiskerprops.linestyle': ['-', validate_linestyle], 'boxplot.capprops.color': ['k', validate_color], 'boxplot.capprops.linewidth': [1.0, validate_float], - 'boxplot.capprops.linestyle': ['-', six.text_type], + 'boxplot.capprops.linestyle': ['-', validate_linestyle], 'boxplot.medianprops.color': ['C1', validate_color], 'boxplot.medianprops.linewidth': [1.0, validate_float], - 'boxplot.medianprops.linestyle': ['-', six.text_type], + 'boxplot.medianprops.linestyle': ['-', validate_linestyle], 'boxplot.meanprops.color': ['C2', validate_color], 'boxplot.meanprops.marker': ['^', six.text_type], 'boxplot.meanprops.markerfacecolor': ['C2', validate_color], 'boxplot.meanprops.markeredgecolor': ['C2', validate_color], 'boxplot.meanprops.markersize': [6, validate_float], - 'boxplot.meanprops.linestyle': ['--', six.text_type], + 'boxplot.meanprops.linestyle': ['--', validate_linestyle], 'boxplot.meanprops.linewidth': [1.0, validate_float], ## font props @@ -1235,7 +1236,7 @@ def validate_grid_linestyle(ls): 'ytick.direction': ['out', six.text_type], # direction of yticks 'grid.color': ['#b0b0b0', validate_color], # grid color - 'grid.linestyle': ['-', validate_grid_linestyle], # solid + 'grid.linestyle': ['-', validate_linestyle], # solid 'grid.linewidth': [0.8, validate_float], # in points 'grid.alpha': [1.0, validate_float], diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 1b622e120b70..872789690c6a 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -30,7 +30,7 @@ validate_cycler, validate_hatch, validate_hist_bins, - validate_grid_linestyle) + validate_linestyle) mpl.rc('text', usetex=False) @@ -335,7 +335,7 @@ def generate_validator_testcases(valid): 'fail': (('aardvark', ValueError), ) }, - {'validator': validate_grid_linestyle, + {'validator': validate_linestyle, 'success': (('--', '--'), ('dotted', 'dotted'), ('aardvark', 'aardvark'), From d9ff6a8fa85186af19d06553ad823d4cf47b8c50 Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Thu, 9 Feb 2017 19:53:53 +0100 Subject: [PATCH 05/15] Check that strings are valid line styles --- lib/matplotlib/rcsetup.py | 15 ++++++++++++--- lib/matplotlib/tests/test_rcparams.py | 21 +++++++++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index e2d317fa8363..07d6d9fc56f5 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -25,7 +25,7 @@ import warnings import re -from matplotlib.cbook import mplDeprecation +from matplotlib.cbook import mplDeprecation, ls_mapper from matplotlib.fontconfig_pattern import parse_fontconfig_pattern from matplotlib.colors import is_color_like @@ -888,13 +888,22 @@ def validate_animation_writer_path(p): modules["matplotlib.animation"].writers.set_dirty() return p +# A validator dedicated to the named line styles, based on the items in +# ls_mapper, and a list of possible strings read from Line2D.set_linestyle +validate_named_linestyle = ValidateInStrings('linestyle', + list(six.iterkeys(ls_mapper)) + + list(six.itervalues(ls_mapper)) + + ['None', 'none', ' ', ''], + ignorecase=False) +# A validator for all possible line styles, the named ones *and* +# the on-off ink sequences. def validate_linestyle(ls): # Named line style, like u'--' or u'solid' if isinstance(ls, six.text_type): - return ls + return validate_named_linestyle(ls) - # Sequence *of even length* of on and off ink (in points). + # On-off ink (in points) sequence *of even length*. # Offset is set to None. try: if len(ls) % 2 != 0: diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 872789690c6a..180a315d1220 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -336,18 +336,23 @@ def generate_validator_testcases(valid): ) }, {'validator': validate_linestyle, - 'success': (('--', '--'), - ('dotted', 'dotted'), - ('aardvark', 'aardvark'), + 'success': (('-', '-'), ('solid', 'solid'), + ('--', '--'), ('dashed', 'dashed'), + ('-.', '-.'), ('dashdot', 'dashdot'), + (':', ':'), ('dotted', 'dotted'), + ('', ''), (' ', ' '), + ('None', 'None'), ('none', 'none'), (['1.23', '4.56'], (None, [1.23, 4.56])), ([1.23, 456], (None, [1.23, 456.0])), ([1, 2, 3, 4], (None, [1.0, 2.0, 3.0, 4.0])), ), - 'fail': (((None, [1, 2]), ValueError), - ((0, [1, 2]), ValueError), - ((-1, [1, 2]), ValueError), - ([1, 2, 3], ValueError), - (1.23, ValueError) + 'fail': (('aardvark', ValueError), # not a valid string + ('DoTtEd', ValueError), # validation is case-sensitive + ((None, [1, 2]), ValueError), # (offset, dashes) is not OK + ((0, [1, 2]), ValueError), # idem + ((-1, [1, 2]), ValueError), # idem + ([1, 2, 3], ValueError), # not a sequence of even length + (1.23, ValueError) # not a sequence ) } ) From 44c3fde4a070731c8fb1db8aa6422b5f0be59461 Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Thu, 9 Feb 2017 20:39:56 +0100 Subject: [PATCH 06/15] fix PEP8 --- lib/matplotlib/tests/test_rcparams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 180a315d1220..b149f1437db7 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -351,7 +351,7 @@ def generate_validator_testcases(valid): ((None, [1, 2]), ValueError), # (offset, dashes) is not OK ((0, [1, 2]), ValueError), # idem ((-1, [1, 2]), ValueError), # idem - ([1, 2, 3], ValueError), # not a sequence of even length + ([1, 2, 3], ValueError), # not a sequence of even length (1.23, ValueError) # not a sequence ) } From e8032dff30c077a6e3afece034b59c9294ee4df0 Mon Sep 17 00:00:00 2001 From: "Adrien F. Vincent" Date: Fri, 10 Feb 2017 10:26:15 +0100 Subject: [PATCH 07/15] use validate_linestyle even for rcParam 'contour.negative_linestyle' --- lib/matplotlib/rcsetup.py | 19 +------------------ matplotlibrc.template | 2 +- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 07d6d9fc56f5..ba57766d9c6b 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -530,22 +530,6 @@ def validate_ps_distiller(s): 'top', 'none']) validate_fillstylelist = _listify_validator(validate_fillstyle) -validate_negative_linestyle = ValidateInStrings('negative_linestyle', - ['solid', 'dashed'], - ignorecase=True) - - -def validate_negative_linestyle_legacy(s): - try: - res = validate_negative_linestyle(s) - return res - except ValueError: - dashes = validate_nseq_float(2)(s) - warnings.warn("Deprecated negative_linestyle specification; use " - "'solid' or 'dashed'", - mplDeprecation) - return (0, dashes) # (offset, (solid, blank)) - def validate_corner_mask(s): if s == 'legacy': @@ -1081,8 +1065,7 @@ def validate_linestyle(ls): 'image.composite_image': [True, validate_bool], # contour props - 'contour.negative_linestyle': ['dashed', - validate_negative_linestyle_legacy], + 'contour.negative_linestyle': ['dashed', validate_linestyle], 'contour.corner_mask': [True, validate_corner_mask], # errorbar props diff --git a/matplotlibrc.template b/matplotlibrc.template index e57dfd9ada2d..aaaf32e412c0 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -471,7 +471,7 @@ backend : $TEMPLATE_BACKEND # such as a PDF. ### CONTOUR PLOTS -#contour.negative_linestyle : dashed # dashed | solid +#contour.negative_linestyle : dashed # string or on-off ink sequence #contour.corner_mask : True # True | False | legacy ### ERRORBAR PLOTS From 2673585f66e838175b1406b24dd22d898e1d189e Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Tue, 14 Feb 2017 00:06:09 +0100 Subject: [PATCH 08/15] Reintroduce former public validators for negative contours (but they are not used anymore) --- lib/matplotlib/rcsetup.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index ba57766d9c6b..500e44b67947 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -530,6 +530,22 @@ def validate_ps_distiller(s): 'top', 'none']) validate_fillstylelist = _listify_validator(validate_fillstyle) +validate_negative_linestyle = ValidateInStrings('negative_linestyle', + ['solid', 'dashed'], + ignorecase=True) + + +def validate_negative_linestyle_legacy(s): + try: + res = validate_negative_linestyle(s) + return res + except ValueError: + dashes = validate_nseq_float(2)(s) + warnings.warn("Deprecated negative_linestyle specification; use " + "'solid' or 'dashed'", + mplDeprecation) + return (0, dashes) # (offset, (solid, blank)) + def validate_corner_mask(s): if s == 'legacy': From 7bd9bfe54cf2568ac0df2013e7f322454227abda Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Tue, 14 Feb 2017 00:32:36 +0100 Subject: [PATCH 09/15] make validate_linestyle private and case insensitive (+ adapt relevant test) --- lib/matplotlib/rcsetup.py | 41 ++++++++++++++------------- lib/matplotlib/tests/test_rcparams.py | 8 +++--- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 500e44b67947..72ff9f36a273 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -890,18 +890,21 @@ def validate_animation_writer_path(p): # A validator dedicated to the named line styles, based on the items in # ls_mapper, and a list of possible strings read from Line2D.set_linestyle -validate_named_linestyle = ValidateInStrings('linestyle', - list(six.iterkeys(ls_mapper)) + - list(six.itervalues(ls_mapper)) + - ['None', 'none', ' ', ''], - ignorecase=False) - -# A validator for all possible line styles, the named ones *and* -# the on-off ink sequences. -def validate_linestyle(ls): +_validate_named_linestyle = ValidateInStrings('linestyle', + list(six.iterkeys(ls_mapper)) + + list(six.itervalues(ls_mapper)) + + ['None', 'none', ' ', ''], + ignorecase=True) + + +def _validate_linestyle(ls): + """ + A validator for all possible line styles, the named ones *and* + the on-off ink sequences. + """ # Named line style, like u'--' or u'solid' if isinstance(ls, six.text_type): - return validate_named_linestyle(ls) + return _validate_named_linestyle(ls) # On-off ink (in points) sequence *of even length*. # Offset is set to None. @@ -942,7 +945,7 @@ def validate_linestyle(ls): # line props 'lines.linewidth': [1.5, validate_float], # line width in points - 'lines.linestyle': ['-', validate_linestyle], # solid line + 'lines.linestyle': ['-', _validate_linestyle], # solid line 'lines.color': ['C0', validate_color], # first color in color cycle 'lines.marker': ['None', six.text_type], # marker name 'lines.markeredgewidth': [1.0, validate_float], @@ -991,31 +994,31 @@ def validate_linestyle(ls): 'boxplot.flierprops.markerfacecolor': ['none', validate_color_or_auto], 'boxplot.flierprops.markeredgecolor': ['k', validate_color], 'boxplot.flierprops.markersize': [6, validate_float], - 'boxplot.flierprops.linestyle': ['none', validate_linestyle], + 'boxplot.flierprops.linestyle': ['none', _validate_linestyle], 'boxplot.flierprops.linewidth': [1.0, validate_float], 'boxplot.boxprops.color': ['k', validate_color], 'boxplot.boxprops.linewidth': [1.0, validate_float], - 'boxplot.boxprops.linestyle': ['-', validate_linestyle], + 'boxplot.boxprops.linestyle': ['-', _validate_linestyle], 'boxplot.whiskerprops.color': ['k', validate_color], 'boxplot.whiskerprops.linewidth': [1.0, validate_float], - 'boxplot.whiskerprops.linestyle': ['-', validate_linestyle], + 'boxplot.whiskerprops.linestyle': ['-', _validate_linestyle], 'boxplot.capprops.color': ['k', validate_color], 'boxplot.capprops.linewidth': [1.0, validate_float], - 'boxplot.capprops.linestyle': ['-', validate_linestyle], + 'boxplot.capprops.linestyle': ['-', _validate_linestyle], 'boxplot.medianprops.color': ['C1', validate_color], 'boxplot.medianprops.linewidth': [1.0, validate_float], - 'boxplot.medianprops.linestyle': ['-', validate_linestyle], + 'boxplot.medianprops.linestyle': ['-', _validate_linestyle], 'boxplot.meanprops.color': ['C2', validate_color], 'boxplot.meanprops.marker': ['^', six.text_type], 'boxplot.meanprops.markerfacecolor': ['C2', validate_color], 'boxplot.meanprops.markeredgecolor': ['C2', validate_color], 'boxplot.meanprops.markersize': [6, validate_float], - 'boxplot.meanprops.linestyle': ['--', validate_linestyle], + 'boxplot.meanprops.linestyle': ['--', _validate_linestyle], 'boxplot.meanprops.linewidth': [1.0, validate_float], ## font props @@ -1081,7 +1084,7 @@ def validate_linestyle(ls): 'image.composite_image': [True, validate_bool], # contour props - 'contour.negative_linestyle': ['dashed', validate_linestyle], + 'contour.negative_linestyle': ['dashed', _validate_linestyle], 'contour.corner_mask': [True, validate_corner_mask], # errorbar props @@ -1244,7 +1247,7 @@ def validate_linestyle(ls): 'ytick.direction': ['out', six.text_type], # direction of yticks 'grid.color': ['#b0b0b0', validate_color], # grid color - 'grid.linestyle': ['-', validate_linestyle], # solid + 'grid.linestyle': ['-', _validate_linestyle], # solid 'grid.linewidth': [0.8, validate_float], # in points 'grid.alpha': [1.0, validate_float], diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index b149f1437db7..009e03e42d11 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -30,7 +30,7 @@ validate_cycler, validate_hatch, validate_hist_bins, - validate_linestyle) + _validate_linestyle) mpl.rc('text', usetex=False) @@ -335,19 +335,19 @@ def generate_validator_testcases(valid): 'fail': (('aardvark', ValueError), ) }, - {'validator': validate_linestyle, + {'validator': _validate_linestyle, # NB: case-insensitive 'success': (('-', '-'), ('solid', 'solid'), ('--', '--'), ('dashed', 'dashed'), ('-.', '-.'), ('dashdot', 'dashdot'), (':', ':'), ('dotted', 'dotted'), ('', ''), (' ', ' '), - ('None', 'None'), ('none', 'none'), + ('None', 'none'), ('none', 'none'), + ('DoTtEd', 'dotted'), (['1.23', '4.56'], (None, [1.23, 4.56])), ([1.23, 456], (None, [1.23, 456.0])), ([1, 2, 3, 4], (None, [1.0, 2.0, 3.0, 4.0])), ), 'fail': (('aardvark', ValueError), # not a valid string - ('DoTtEd', ValueError), # validation is case-sensitive ((None, [1, 2]), ValueError), # (offset, dashes) is not OK ((0, [1, 2]), ValueError), # idem ((-1, [1, 2]), ValueError), # idem From ad219649e0d0e5de6abb1e2ab552db900f76813f Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Tue, 14 Feb 2017 00:43:13 +0100 Subject: [PATCH 10/15] Remove deprecation warning in 'validate_negative_linestyle_legacy' --- lib/matplotlib/rcsetup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 72ff9f36a273..11c4c1e6a16a 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -541,9 +541,6 @@ def validate_negative_linestyle_legacy(s): return res except ValueError: dashes = validate_nseq_float(2)(s) - warnings.warn("Deprecated negative_linestyle specification; use " - "'solid' or 'dashed'", - mplDeprecation) return (0, dashes) # (offset, (solid, blank)) From 7ab75f5eddf02007f90ff694a94ed19a9f1630e5 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Tue, 14 Feb 2017 01:23:21 +0100 Subject: [PATCH 11/15] Deprecate former validation schemes used by 'contour.negative_linestyle' --- lib/matplotlib/rcsetup.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 11c4c1e6a16a..6c292667832e 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -25,7 +25,7 @@ import warnings import re -from matplotlib.cbook import mplDeprecation, ls_mapper +from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper from matplotlib.fontconfig_pattern import parse_fontconfig_pattern from matplotlib.colors import is_color_like @@ -530,11 +530,22 @@ def validate_ps_distiller(s): 'top', 'none']) validate_fillstylelist = _listify_validator(validate_fillstyle) -validate_negative_linestyle = ValidateInStrings('negative_linestyle', - ['solid', 'dashed'], - ignorecase=True) +_validate_negative_linestyle = ValidateInStrings('negative_linestyle', + ['solid', 'dashed'], + ignorecase=True) +@deprecated('3.0.0?', pending=True, + addendum=(" See 'validate_negative_linestyle_legacy' " + + "deprecation warning for more information.")) +def validate_negative_linestyle(s): + _validate_negative_linestyle(s) + + +@deprecated('3.0.0?', pending=True, + addendum=(" The 'contour.negative_linestyle' rcParam now " + + "follows the same validation as the other rcParams " + + "that are related to line style.")) def validate_negative_linestyle_legacy(s): try: res = validate_negative_linestyle(s) From 59328e6fb11808e67cb1e74edb17ffe978fe0753 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Tue, 14 Feb 2017 01:41:25 +0100 Subject: [PATCH 12/15] Fix typo (a forgotten 'return' statement...) --- lib/matplotlib/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 6c292667832e..5e0535d41b8d 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -539,7 +539,7 @@ def validate_ps_distiller(s): addendum=(" See 'validate_negative_linestyle_legacy' " + "deprecation warning for more information.")) def validate_negative_linestyle(s): - _validate_negative_linestyle(s) + return _validate_negative_linestyle(s) @deprecated('3.0.0?', pending=True, From 70e87c81945ec1fbb1d5871af13d30fe498b48ec Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Fri, 17 Feb 2017 09:12:02 +0100 Subject: [PATCH 13/15] Fix the deprecation decorators --- lib/matplotlib/rcsetup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 5e0535d41b8d..cd43c354f715 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -535,14 +535,14 @@ def validate_ps_distiller(s): ignorecase=True) -@deprecated('3.0.0?', pending=True, +@deprecated('2.1', addendum=(" See 'validate_negative_linestyle_legacy' " + "deprecation warning for more information.")) def validate_negative_linestyle(s): return _validate_negative_linestyle(s) -@deprecated('3.0.0?', pending=True, +@deprecated('2.1', addendum=(" The 'contour.negative_linestyle' rcParam now " + "follows the same validation as the other rcParams " + "that are related to line style.")) From c060842c8352d41822958f3db8c122dff1b1cc37 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Fri, 17 Feb 2017 09:12:45 +0100 Subject: [PATCH 14/15] Add a what's new entry --- .../validation_of_linestyle_rcparams.rst | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/users/whats_new/validation_of_linestyle_rcparams.rst diff --git a/doc/users/whats_new/validation_of_linestyle_rcparams.rst b/doc/users/whats_new/validation_of_linestyle_rcparams.rst new file mode 100644 index 000000000000..794adbf7387a --- /dev/null +++ b/doc/users/whats_new/validation_of_linestyle_rcparams.rst @@ -0,0 +1,31 @@ +Validation of line style rcParams +--------------------------------- + +Stricter validation +``````````````````` +The validation of rcParams that are related to line styles +(``lines.linestyle``, ``boxplot.*.linestyle``, ``grid.linestyle`` and +``contour.negative_linestyle``) now effectively checks that the values +are valid line styles. Strings like ``dashed`` or ``--`` are accepted, +as well as even-length sequences of on-off ink like ``[1, 1.65]``. In +this latter case, the offset value is handled internally and should *not* +be provided by the user. + +The validation is case-insensitive. + +Deprecation of the former validators for ``contour.negative_linestyle`` +``````````````````````````````````````````````````````````````````````` +The new validation scheme replaces the former one used for the +``contour.negative_linestyle`` rcParams, that was limited to ``solid`` +and ``dashed`` line styles. + +The former public validation functions ``validate_negative_linestyle`` +and ``validate_negative_linestyle_legacy`` will be deprecated in 2.1 and +may be removed in 2.3. There are no public functions to replace them. + +Examples of use +``````````````` +:: + +....grid.linestyle : (1, 3) # loosely dotted grid lines + contour.negative_linestyle : dashdot # previously only solid or dashed From aabf385f53d049d6dbd80ec7236d52845b303a6a Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Fri, 17 Feb 2017 09:23:04 +0100 Subject: [PATCH 15/15] Fix a typo with the example in the what's new entry --- doc/users/whats_new/validation_of_linestyle_rcparams.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/users/whats_new/validation_of_linestyle_rcparams.rst b/doc/users/whats_new/validation_of_linestyle_rcparams.rst index 794adbf7387a..d8fd823593f2 100644 --- a/doc/users/whats_new/validation_of_linestyle_rcparams.rst +++ b/doc/users/whats_new/validation_of_linestyle_rcparams.rst @@ -27,5 +27,5 @@ Examples of use ``````````````` :: -....grid.linestyle : (1, 3) # loosely dotted grid lines + grid.linestyle : (1, 3) # loosely dotted grid lines contour.negative_linestyle : dashdot # previously only solid or dashed