Skip to content
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

Deprecate automatically registering matplotlib units (partial revert of 0.21.0) #18301

Closed
jorisvandenbossche opened this issue Nov 15, 2017 · 5 comments
Labels
Deprecate Functionality to remove in pandas Visualization plotting
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Nov 15, 2017

Given the feedback we have got (#18153, #18192, #18212, #18283, matplotlib/matplotlib#9577, matplotlib/matplotlib#9610, matplotlib/matplotlib#9771, pydata/xarray#166), it seems we underestimated the impact and we should consider (partly) reverting this change to properly deprecate it instead.

This should also give matplotlib the time to implement basic datetime64 support (matplotlib/matplotlib#9610, matplotlib/matplotlib#9779)

Depending on how we can do this, this might have the consequence that have to undo temporarily the lazy import of matplotlib (affecting the import time). See also discussion in #18283

Opening this issue to keep track of it, should be decided/done for 0.21.1

@TomAugspurger
Copy link
Contributor

Yeah, we should add back the converter registration on pandas import.

I have a branch started that should be able to emit a warning when people rely on the implicit registration, so we'll be able to deprecate this cleanly.

@jorisvandenbossche
Copy link
Member Author

And then doing the registering manually will overwrite the deprecated units as a way to avoid the warning? And also using pandas plotting functionality the first time will do the same?

Side question: now we recommend people to do from pandas.tseries import converter, but IMO it would be more logical to have this in pandas.plotting ? We can't remove (or even deprecate will be annoying) the tseries one (certainly to support multiple pandas versions), but maybe we could consider moving it to pandas.plotting as well and start using that in our docs?

@TomAugspurger
Copy link
Contributor

Here's the behavior:

In [1]: import pandas as pd
imp
In [2]: import matplotlib.pyplot as plt

In [3]: fig, ax = plt.subplots()

In [4]: s = pd.Series(range(12), index=pd.date_range('2017', periods=12))
   ...:

In [5]: ax.plot(s)
/Users/taugspurger/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/plotting/_converter.py:77: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.

To register the converters:
        >>> from pandas.tseries import converter
        >>> converter.register()
  warnings.warn(msg, FutureWarning)
Out[5]: [<matplotlib.lines.Line2D at 0x10e18eb38>]

vs.

In [1]: import pandas as pd

In [2]: import matplotlib.pyplot as plt

In [3]: from pandas.tseries import converter

In [4]: converter.register()

In [5]: fig, ax = plt.subplots()

In [6]: s = pd.Series(range(12), index=pd.date_range('2017', periods=12))

In [7]: ax.plot(s)
Out[7]: [<matplotlib.lines.Line2D at 0x1097c76d8>]

(the implementation isn't the prettiest, but it works).

Happy to move the recommended import location (while keeping pandas.tseries there for compat).

@jorisvandenbossche
Copy link
Member Author

that looks good!

@ThomasDevoogdt
Copy link

ThomasDevoogdt commented Jan 11, 2020

In the meantime, @TomAugspurger's answer is also due for an update.

Original answer:

import pandas as pd

pd.tseries.converter.register()

gives:

<ipython-input-20-65fd42b949c8>:3: FutureWarning: 'pandas.tseries.converter.register' has been moved and renamed to 'pandas.plotting.register_matplotlib_converters'. 
  pd.tseries.converter.register()

Update:

import pandas as pd

pd.plotting.register_matplotlib_converters()

Apparently, I get this issue because I'm not using the matplotlib directly, but via seaborn's data visualization library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Visualization plotting
Projects
None yet
Development

No branches or pull requests

3 participants