File tree 3 files changed +15
-7
lines changed
3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -1926,6 +1926,8 @@ class _rcParam_helper:
1926
1926
@classmethod
1927
1927
def set_converter (cls , s ):
1928
1928
"""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"' )
1929
1931
cls .conv_st = s
1930
1932
cls .register_converters ()
1931
1933
Original file line number Diff line number Diff line change @@ -176,20 +176,24 @@ def validate_bool_maybe_none(b):
176
176
177
177
178
178
def _validate_date_converter (s ):
179
+ if s is None :
180
+ return
179
181
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 )
183
189
184
190
185
191
def _validate_date_int_mult (s ):
186
192
if s is None :
187
193
return
188
194
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 )
193
197
194
198
195
199
def _validate_tex_preamble (s ):
Original file line number Diff line number Diff line change @@ -977,6 +977,8 @@ def test_change_converter():
977
977
fig .canvas .draw ()
978
978
assert ax .get_xticklabels ()[0 ].get_text () == 'Jan 01 2020'
979
979
assert ax .get_xticklabels ()[1 ].get_text () == 'Jan 15 2020'
980
+ with pytest .warns (UserWarning ) as rec :
981
+ plt .rcParams ['date.converter' ] = 'boo'
980
982
981
983
982
984
def test_change_interval_multiples ():
You can’t perform that action at this time.
0 commit comments