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

Skip to content

Commit ca01a39

Browse files
authored
Merge pull request #17869 from jklymak/fix-date-rcparam
FIX: new date rcParams weren't being evaluated
2 parents b803891 + 3c84dc3 commit ca01a39

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,24 @@ 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+
return
187+
import matplotlib.dates as mdates
188+
mdates._rcParam_helper.set_converter(s)
183189

184190

185191
def _validate_date_int_mult(s):
186192
if s is None:
187193
return
188194
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)
195+
import matplotlib.dates as mdates
196+
mdates._rcParam_helper.set_int_mult(s)
193197

194198

195199
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)