Skip to content

FIX: new date rcParams weren't being evaluated #17869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use cbook._check_in_list()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s is just a string, not a dict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_check_in_list doesn't check dicts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work:

cbook._check_in_list(['concise', 'auto'], s=s)

The example in the docstring is misleading; as far as I can see, this would rarely if ever be called with more than one keyword argument. The reason it requires a keyword argument is that this supplies a name for the variable when reporting the error.

raise ValueError('Converter must be one of "concise" or "auto"')
cls.conv_st = s
cls.register_converters()

Expand Down
18 changes: 11 additions & 7 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down