-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[MNT]: Cleanup ticklabel_format (style=) #26801
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
Conversation
…fixing extra logic.
Fixing if condition.
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
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.
Thank you for your work on this @pedrompecanha! Just a couple of comments on the implementation...
This line will break if style
is None
, so perhaps should be moved into the else
of your new if loop below.
matplotlib/lib/matplotlib/axes/_base.py
Line 3277 in 6fa5045
style = style.lower() |
lib/matplotlib/axes/_base.py
Outdated
is_sci_style = _api.check_getitem(STYLES, style=style) | ||
STYLES = {'sci': True, 'scientific': True, 'plain': False} | ||
if style is None: | ||
is_sci_style = False |
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_sci_style = False | |
is_sci_style = None |
None
here should mean that the style is not changed from what it previously was. Setting is_sci_style
also to None
achieves that.
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.
I'm changing it so that everything is in the dictionary. I believe it solves it more effectively. About setting it to None or False, I thought this variable should be either True or False but, after reading the logic after it, I've seen it can be None, indeed.
The typing stub file will also need updating to match the new signature matplotlib/lib/matplotlib/axes/_base.pyi Lines 282 to 291 in 6fa5045
|
lib/matplotlib/axes/_base.py
Outdated
@@ -3283,8 +3284,11 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None, | |||
except (ValueError, TypeError) as err: | |||
raise ValueError("scilimits must be a sequence of 2 integers" | |||
) from err | |||
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None} | |||
is_sci_style = _api.check_getitem(STYLES, style=style) | |||
STYLES = {'sci': True, 'scientific': True, 'plain': False} |
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.
An option here (and also in case someone has set style=''
explicitly), is to do:
STYLES = {'sci': True, 'scientific': True, 'plain': False} | |
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None} | |
is_sci_style = _api.check_getitem(STYLES, style=style) |
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.
in case someone has set
style=''
explicitly
That's a good point. I suggest to also add a comment that ''
is included for backwards-compatibility, as I do not think it would be obvious to future readers of the code.
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.
I added the comment and added the empty string into the dictionary. Actually, I was playing tennis and thought about how my changes weren't backwards compatible. Nice to see we are in the same page :)
…ionary and added stub parameter alternative.
lib/matplotlib/axes/_base.py
Outdated
Whether to use scientific notation. | ||
The formatter default is to use scientific notation. | ||
Sci is equivalent to scientific. | ||
The '' option is included solely for backwards-compatibility. |
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.
Apologies, I think I was unclear. I meant to add a code comment where the dictionary is defined, so that future developers know that it’s there for a reason. I don’t think it’s needed in the docstring.
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.
Done in the latest commit!
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.
The last test failure comes with instructions (which I admit are new to me!)
lib/matplotlib/axes/_base.py
Outdated
@@ -3283,7 +3284,9 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None, | |||
except (ValueError, TypeError) as err: | |||
raise ValueError("scilimits must be a sequence of 2 integers" | |||
) from err | |||
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None} | |||
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None} | |||
# 'sci' is equivalent to 'scientific'. |
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.
I think the fact that 'sci' and ‘scientific' are equivalent should be in the docstring, as this is useful information for the user.
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.
Just put them back there! As for the pyplot issue, I attempted following the instructions and it told me, in my system, that the file got reformatted. Let's see how it goes!
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.
It seems the pyplot change has not appeared here on GitHub...
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.
Yeah! I tried running the command again, but the file remained unchanged. I tried to change the file by hand, although this is not encouraged, and the commit went through on my fork, but it won't open here on Github. Just goes straight to a 404 page. Weird.
Here is the final change I made: pedrompecanha@3cf0234
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.
I believe it has gone through now. Must have been a GitHub instability. The tests seem to be running well, although I'm kind of scared of having to change this file by hand. Thoughts?
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.
Your manual change matches what I get by running the script, so I think it's OK.
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.
Thanks @pedrompecanha, I think this is in good shape now. I just have a tiny suggestion on the docstring.
…ers that default to None. Co-authored-by: Ruth Comer <[email protected]>
@rcomer, @timhoffm and @oscargus, thank you for the support and patience during this process! I'd like to ask that, if you find any similar cleanup or refactoring tasks, if you could please tag me, as I'll be really active in the next 1-2 months in here. Of course, if that is allowed by the rules of the project. I'll try my best to solve the issues. Again, thank you! |
Thanks @pedrompecanha and congratulations on your first contribution to Matplotlib! We hope to see you back. |
PR summary
Fixes #25974.
-->
PR checklist