Pandas: Deprecate automatically registering matplotlib units (partial revert of 0.21.0)

Created on 15 Nov 2017  路  5Comments  路  Source: pandas-dev/pandas

Given the feedback we have got (https://github.com/pandas-dev/pandas/issues/18153, https://github.com/pandas-dev/pandas/issues/18192, https://github.com/pandas-dev/pandas/issues/18212, https://github.com/pandas-dev/pandas/issues/18283, https://github.com/matplotlib/matplotlib/issues/9577, https://github.com/matplotlib/matplotlib/issues/9610, https://github.com/matplotlib/matplotlib/issues/9771, https://github.com/pydata/xarray/issues/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 (https://github.com/matplotlib/matplotlib/issues/9610, https://github.com/matplotlib/matplotlib/pull/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 https://github.com/pandas-dev/pandas/issues/18283

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

Deprecate Visualization

Most helpful comment

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).

All 5 comments

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.

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?

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).

that looks good!

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.

Was this page helpful?
0 / 5 - 0 ratings