Skip to content

deregister_matplotlib_converters() in 0.25 incorrectly removes Matplotlib converters #27479

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
dstansby opened this issue Jul 19, 2019 · 9 comments · Fixed by #27481
Closed
Labels
Regression Functionality that used to work in a prior pandas version Visualization plotting
Milestone

Comments

@dstansby
Copy link
Contributor

Consider

import matplotlib.units as munits
import pandas as pd
pd.plotting.deregister_matplotlib_converters()

print(pd.__version__)
for key in munits.registry:
    print(key, '\t', munits.registry[key])

deregister_matplotlib_converters() should only remove pandas converters, and not any other converters in the MPL units registry, but in pandas 0.25 it removes some of the Matplotlib converters.

Problem description

For pandas 0.24 this prints:

0.24.2
<class 'decimal.Decimal'> 	 <matplotlib.units.DecimalConverter object at 0x1135515f8>
<class 'datetime.datetime'> 	 <matplotlib.dates.DateConverter object at 0x11ed79cc0>
<class 'datetime.date'> 	 <matplotlib.dates.DateConverter object at 0x11ed79c88>
<class 'numpy.datetime64'> 	 <matplotlib.dates.DateConverter object at 0x11ed79c50>

But for pandas 0.25 it gives

0.25.0
<class 'decimal.Decimal'> 	 <matplotlib.units.DecimalConverter object at 0x1133cd588>

This means pandas.plotting.deregister_matplotlib_converters is removing some of the built in matplotlib converters from the units registry when it shouldn't be; this is causing some of our tests to break upstream (xref matplotlib/matplotlib#14859)

@dstansby
Copy link
Contributor Author

Ah, actually I think the problem might be that pandas registers it's own converters, and then deregister_matplotlib_converters() deletes them (correct behaviour), but does not restore the original Matplotlib converters. I think #27480 is the easiest way to solve this issue, by just relying on the Matplotlib converters when available.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jul 19, 2019

deregister_matplotlib_converters should restore the original ones. I'd prefer fixing the restoration to outright removing the old ones. I think we got pushback last time we changed this.

@dstansby
Copy link
Contributor Author

Why the pushback (out of interest)? Naïvely it seems to me that maintaining two different implementations (one in mpl, one in pandas) of the python-native datetime converters seems wrong to me; there is only one correct way to do the conversion.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jul 19, 2019 via email

@jklymak
Copy link
Contributor

jklymak commented Jul 19, 2019

I think it'd be great if pandas just used Matplotlib's converters, but can easily imagine that would cause issues, particularly as our converters changed around 3.0. It just seems like a nuisance to have two sets of converters.

But for sure, it would be nice if the matplotlib converters were re-loaded when the panda ones are deregistered 😉

@TomAugspurger
Copy link
Contributor

I'm 100% on board with just using Matplotlib. I don't think any of the current pandas maintainers understand of converters :) Just need to figure out a way to get there that isn't too disruptive.

@jklymak
Copy link
Contributor

jklymak commented Jul 19, 2019

Yeah, I imagine back-compatabilty would be the biggest problem if you are still supporting MPL 2.x

@jreback jreback added the Visualization plotting label Jul 20, 2019
@jreback jreback added this to the 0.25.1 milestone Jul 20, 2019
@jreback jreback added the Regression Functionality that used to work in a prior pandas version label Jul 20, 2019
@jorisvandenbossche
Copy link
Member

I'm 100% on board with just using Matplotlib. I don't think any of the current pandas maintainers understand of converters :) Just need to figure out a way to get there that isn't too disruptive.

That's not fully correct I think. The pandas converters do provide more features and a better user experience, but, we are speaking then about the Period-based converters (and we do convert regular datetime64 timeseries to periods).

@jorisvandenbossche
Copy link
Member

Anyway, justed wanted to say: it is not that easy to just move to matplotlib's converters. But if people are interested in discussing this more in depth, let's open a new issue for it (as we should for sure fix the regression of not restoring the converters correctly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Visualization plotting
Projects
None yet
5 participants