-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Change matplotlib formatter registration #28722
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
API: Change matplotlib formatter registration #28722
Conversation
@@ -71,27 +59,12 @@ def test_register_by_default(self): | |||
call = [sys.executable, "-c", code] | |||
assert subprocess.check_call(call) == 0 | |||
|
|||
def test_warns(self): | |||
plt = pytest.importorskip("matplotlib.pyplot") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to check that we have not registered things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we do that indirectly with the code check... If we haven't imported matplotlib, then we know we haven't registered anything.
def register(explicit=True): | ||
# Renamed in pandas.plotting.__init__ | ||
global _WARN | ||
def pandas_converters_deco(func): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this needs to be a decorator? Perhaps a style preference but I would find it easier to grok if the context manager was used where required in the actual plotting methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need. I mainly did it for a smaller diff / less indentation :)
Happy to go either way here.
All green here now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The auto behaviour seems to work nicely based on a quick test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small doc comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, nice work. Lgtm, just an idea on implementation and naming, but happy to see this merged with or without thar.
Should be good to go. |
Thanks! |
This PR does two things
Background: pandas used to register formatters for Period, datetime, date, and time. This formatters affected plots created using matplotlib only, not pandas. For various reasons (including import time) we don't want to do this on an
import pandas
.A minimal change would be to just not do the registration on
import pandas
. Users would either manually do it, or pandas does it automatically when we do DataFrame.plot. The downside of pandas doing it automatically is then in the followingfig1 and fig2 will be different because pandas has implicilty registered formatters.
The
auto
option will automatically register the formatters, make the plot, then deregister the formatters.Closes #18720