From 3c84dc30a3d73dca992c064d61aae50ad4049dab Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 9 Jul 2020 09:52:02 -0700 Subject: [PATCH] FIX: new date rcParams weren't being evaluated --- lib/matplotlib/dates.py | 2 ++ lib/matplotlib/rcsetup.py | 18 +++++++++++------- lib/matplotlib/tests/test_dates.py | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index df916d44b60c..131eac48093c 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1926,6 +1926,8 @@ class _rcParam_helper: @classmethod def set_converter(cls, s): """Called by validator for rcParams date.converter""" + if s not in ['concise', 'auto']: + raise ValueError('Converter must be one of "concise" or "auto"') cls.conv_st = s cls.register_converters() diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 7abde998778a..cb474ea4e4d2 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -176,20 +176,24 @@ def validate_bool_maybe_none(b): def _validate_date_converter(s): + if s is None: + return s = validate_string(s) - mdates = sys.modules.get("matplotlib.dates") - if mdates: - mdates._rcParam_helper.set_converter(s) + if s not in ['auto', 'concise']: + cbook._warn_external(f'date.converter string must be "auto" ' + f'or "concise", not "{s}". Check your ' + 'matplotlibrc') + return + import matplotlib.dates as mdates + mdates._rcParam_helper.set_converter(s) def _validate_date_int_mult(s): if s is None: return s = validate_bool(s) - # only do this if dates is already imported... - mdates = sys.modules.get("matplotlib.dates") - if mdates: - mdates._rcParam_helper.set_int_mult(s) + import matplotlib.dates as mdates + mdates._rcParam_helper.set_int_mult(s) def _validate_tex_preamble(s): diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 70fa15a17d0f..47634befc013 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -977,6 +977,8 @@ def test_change_converter(): fig.canvas.draw() assert ax.get_xticklabels()[0].get_text() == 'Jan 01 2020' assert ax.get_xticklabels()[1].get_text() == 'Jan 15 2020' + with pytest.warns(UserWarning) as rec: + plt.rcParams['date.converter'] = 'boo' def test_change_interval_multiples():