File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -176,20 +176,24 @@ def validate_bool_maybe_none(b):
176176
177177
178178def _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
185191def _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
195199def _validate_tex_preamble (s ):
Original file line number Diff line number Diff 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
982984def test_change_interval_multiples ():
You can’t perform that action at this time.
0 commit comments