-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Regression in datetime handling in plots #6102
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
Comments
The registration happens here, added in #1669 in 2017: Lines 34 to 39 in 5e8de55
Is the registration even needed anymore I wonder? Matplotlib started supporting datetime64 in 2018: https://github.com/matplotlib/matplotlib/releases/tag/v2.2.0 |
Hi @Illviljan that is correct. However after #5794 xarray is more aggressively making the pandas choice for the user. I'll play with it a bit to see if just removing your explicit registration fixes the problem. However changing the datetime converter would be a breaking change (to your plotting) that I'm not sure you want. This is a tricky problem that I'm not sure matplotlib has handled properly (full disclosure, I'm on the mpl dev team and usually handle datetime issues, though I didn't design our units registry). Having a registry that users can change is very flexible. However when downstream libraries like xarray or pandas affect user plotting just by importing the package, it leads to considerable confusion as users don't necessarily know this has happened or how to get back to the Matplotlib default. Particularly if they are not using the package's plotting utilities, but just the other features and/or data types (for instance I love xarray and use it all the time in my data analysis, but I rarely use the plotting convenience functions) |
There's a pr for reverting, #6064, for a separate reason that we probably should merge soon. I simply don't understand what that registration does, it might well be just a quick fix in a time when mpl didn't support datetimes and it might be good idea to simplify and remove it in a future pr. |
So is #6109 enough to permanently fix this? |
As I'm away from a computer for a few days so can't double check, but I did bisect the problem to the pr that was reverted. However you could keep this open for a more fulsome discussion of date handling and whether xarray wants to use the pandas or matplotlib converters. I would actually be pretty happy if pandas also just used matplotlibs converters - we already jump through some hoops to make data frames work. |
IMO matplotlib is fine This code is from before matplotlib supported datetime64. |
I checked the code from above, and it has the Matplotlib unit handlers rather than the pandas |
BTW, maybe you could/should add a test for this behaviour? |
Do you have an easy test in mind? |
Sure see #6128 |
#5794 (ea28861) introduced a regression in whether or not pandas datetime converters are loaded or Matplotlib's. This leads to basic Matplotlib-native plotting failing matplotlib/matplotlib#22023 Previously matplotlib's converters were loaded, now pandas are being loaded, despite the downstream user not ever using xarray's plotting utilities.
test code
Previously:
Now:
As you can see, the pandas converters have been loaded without any use of pandas nor xarray plotting utilities.
Suggestion
Of course if xarray plotting is loaded, you should use and register what date converters you would like (I'd suggest
matplotlib.dates.ConciseConverter
, but your mileage may vary). But I think if the user is just trying to use xarray to load a data set, they should not have decisions made for them about the converter (or any other plotting functions), and to prevent confusion they should get the default matplotlib converter since it handlesdatetime64
just fine.I think it could also be argued that this is a pandas issue, in that just importing pandas should not automatically register their converters unless their plotting is used. ping @TomAugspurger because I thought that was the plan, but apparently things changed. And it indeed appears their converter has a bug in it for matplotlib scatter.
Thanks!
The text was updated successfully, but these errors were encountered: