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

Skip to content

Commit 20a599b

Browse files
committed
FIX: new date rcParams weren't being evaluated
1 parent f8d10f5 commit 20a599b

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

lib/matplotlib/dates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,8 @@ class _rcParam_helper:
19261926
@classmethod
19271927
def set_converter(cls, s):
19281928
"""Called by validator for rcParams date.converter"""
1929+
if s not in ['concise', 'auto']:
1930+
raise ValueError('Converter must be one of "concise" or "auto"')
19291931
cls.conv_st = s
19301932
cls.register_converters()
19311933

lib/matplotlib/rcsetup.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,23 @@ def validate_bool_maybe_none(b):
176176

177177

178178
def _validate_date_converter(s):
179+
if s is None:
180+
return
179181
s = validate_string(s)
180-
mdates = sys.modules.get("matplotlib.dates")
181-
if mdates:
182-
mdates._rcParam_helper.set_converter(s)
182+
if s not in ['auto', 'concise']:
183+
cbook._warn_external(f'date.converter string must be "auto" '
184+
f'or "concise", not "{s}". Check your '
185+
'matplotlibrc')
186+
import matplotlib.dates as mdates
187+
mdates._rcParam_helper.set_converter(s)
183188

184189

185190
def _validate_date_int_mult(s):
186191
if s is None:
187192
return
188193
s = validate_bool(s)
189-
# only do this if dates is already imported...
190-
mdates = sys.modules.get("matplotlib.dates")
191-
if mdates:
192-
mdates._rcParam_helper.set_int_mult(s)
194+
import matplotlib.dates as mdates
195+
mdates._rcParam_helper.set_int_mult(s)
193196

194197

195198
def _validate_tex_preamble(s):

lib/matplotlib/tests/test_dates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ def test_change_converter():
977977
fig.canvas.draw()
978978
assert ax.get_xticklabels()[0].get_text() == 'Jan 01 2020'
979979
assert ax.get_xticklabels()[1].get_text() == 'Jan 15 2020'
980+
with pytest.warns(UserWarning) as rec:
981+
plt.rcParams['date.converter'] = 'boo'
980982

981983

982984
def test_change_interval_multiples():

0 commit comments

Comments
 (0)