Skip to content

No MatplotlibDeprecationWarning for default rcParams #13118

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

Closed
koki-sato opened this issue Jan 6, 2019 · 7 comments · Fixed by #21042
Closed

No MatplotlibDeprecationWarning for default rcParams #13118

koki-sato opened this issue Jan 6, 2019 · 7 comments · Fixed by #21042

Comments

@koki-sato
Copy link

Bug report

Bug summary

I get MatplotlibDeprecationWarning when putting the default rcParams copied by matplotlib.rcParams.copy() into matplotlib.rcParams.update().

Code for reproduction

>>> import matplotlib
>>> matplotlib.__version__
'3.0.2'
>>> rc_params = matplotlib.rcParams.copy()
>>> matplotlib.rcParams.update(rc_params)
/Users/xxxx/.local/share/virtualenvs/xxxx/lib/python3.6/site-packages/matplotlib/__init__.py:855: MatplotlibDeprecationWarning:
examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory.
  "found relative to the 'datapath' directory.".format(key))
/Users/xxxx/.local/share/virtualenvs/xxxx/lib/python3.6/site-packages/matplotlib/__init__.py:846: MatplotlibDeprecationWarning:
The text.latex.unicode rcparam was deprecated in Matplotlib 2.2 and will be removed in 3.1.
  "2.2", name=key, obj_type="rcparam", addendum=addendum)

It is because matplotlib.rcParams.copy() returns dictionary of rcParams and it includes deprecated rcParams like examples.directory and text.latex.unicode. However, examples.directory and text.latex.unicode are included in the default rcParams of matplotlib.

Expected outcome

Do not show MatplotlibDeprecationWarning for default rcParams.

Matplotlib version

  • Operating system: macOS Sierra 10.12.6
  • Matplotlib version: 3.0.2
  • Matplotlib backend: Agg
  • Python version: 3.6.5
  • Jupyter version (if applicable):
  • Other libraries:
@timhoffm
Copy link
Member

timhoffm commented Jan 6, 2019

Until the parameters are actually removed, they are valid and rcParams.copy() must copy them if they are in the config. At least in the present master branch they are not included anymore.

Can you please check your local config file (path can be obtained using matplotlib.matplotlib_fname()) to see if these parameters are set there?

@koki-sato
Copy link
Author

koki-sato commented Jan 6, 2019

@timhoffm Thanks for your comment!

There is an empty matplotlibrc in my project root.

>>> import matplotlib
>>> print(open(matplotlib.matplotlib_fname()).read())

>>> rc_params = matplotlib.rcParams.copy()
>>> rc_params['examples.directory']
''
>>> rc_params['text.latex.unicode']
True

I think examples.directory and text.latex.unicode are included in defaultParams and it is used on setup.

@timhoffm
Copy link
Member

timhoffm commented Jan 6, 2019

You are right. However, I don't have a clear view how to prevent this.

We cannot remove the parameter unconditionally because someone might be relying that it's there.
One option would be to add a skip_deprecated parameter to copy(). However, that seems a bit of an overkill and would also not help in other use-cases like iterating over rcParams.

@koki-sato
Copy link
Author

koki-sato commented Jan 6, 2019

I also don't have any solutions…
However, I think it is inappropriate to display the warning when applying parameters which are included in the default rcParams :(

The most troubling thing on this is that these warnings are displayed when using seaborn and seaborn.reset_orig(). Now, I think this can be controlled in seaborn. So I will create an issue in the seaborn repository.

@QuLogic
Copy link
Member

QuLogic commented Jan 6, 2019

I thought we had some machinery to avoid this (or at least a discussion somewhere already).

@tacaswell
Copy link
Member

I thought we had some machinery to avoid this (or at least a discussion somewhere already).

I think we catch and discard the warnings internally, I suspect seaborn should do the same.

I agree that this is annoying behavior, but I don't see a way around it.

  • not returning deprecated rcParams in copy (and not including them in iteration?) is not great (as things don't round-trip in weird ways). However, if we are sure that the rcparam has no effect (that is we completely ignore its value), this may be a reasonable path, but would be a pretty big API change and would break people who are looking for the deprecated value in the copy with no warning (which will happen next release anyway, but they are at least getting some warning about the key now).
  • not warning if the value is the default value would help this case, but would fail to warn someone doing rcParams['old'] = dflt_value in their code which would start to raise in the future
  • warn based on the type of the object passed into .update, but that seems a bit too magical

@koki-sato
Copy link
Author

I see. Thank you for your responses!

I hit upon two solutions, but I don't think they are good.

  1. Deprecated rcParams should be removed from default value.
    This will solve the problem, but it will be a big change.

  2. Preparing a function which returns a instance of matplotlib.RcParams
    matplotlib.rcParams.update(matplotlib.rcParamsDefault) don't show warnings. This is because matplotlib.rcParamsDefault is not a dictonary but a instance of matplotlib.RcParams. So, It is also a way to prepare the following method.

class RcParams(MutableMapping, dict):
    [...]
    def wrapped_copy(self):
	   with warnings.catch_warnings():
	       warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
	       return RcParams(self.copy())

rlabbe added a commit to rlabbe/Kalman-and-Bayesian-Filters-in-Python that referenced this issue Apr 27, 2020
matplotlib is issuing a deprecation warning whenever you use rcParams,
even if you are not using one of the deprecated values. This is
very annoying. I eat the deprecation while using rcParams.

matplotlib/matplotlib#13118
@QuLogic QuLogic added this to the v3.6.0 milestone Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants