-
Notifications
You must be signed in to change notification settings - Fork 224
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
Convert booleans arguments in build_arg_string, not in kwargs_to_strings #1125
Conversation
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 some minor comments for now. I think there's some room for improvement but will suggest more later (possibly after the weekend).
Co-authored-by: Wei Ji <[email protected]>
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.
A few suggestions, mostly on refactoring the if-then blocks. Feel free to disagree if it feels less readable to you.
|
||
if angle is True: | ||
kwargs["F"] += "+a" | ||
elif isinstance(angle, (int, float, str)): | ||
kwargs["F"] += f"+a{str(angle)}" |
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 thinking ahead to resolve #483 (allowing list inputs to angle/list/justify), we could simply use if angle
(returns True for list/int/float/str inputs) like so:
if angle is True: | |
kwargs["F"] += "+a" | |
elif isinstance(angle, (int, float, str)): | |
kwargs["F"] += f"+a{str(angle)}" | |
if angle: | |
kwargs["F"] += "+a" | |
if isinstance(angle, (int, float, str)): | |
kwargs["F"] += str(angle) |
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.
Ok, as you wish then.
if font is True: | ||
kwargs["F"] += "+f" | ||
elif isinstance(font, str): | ||
kwargs["F"] += f"+f{font}" |
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.
if font is True: | |
kwargs["F"] += "+f" | |
elif isinstance(font, str): | |
kwargs["F"] += f"+f{font}" | |
if font: | |
kwargs["F"] += "+f" | |
if isinstance(font, str): | |
kwargs["F"] += font |
if justify is True: | ||
kwargs["F"] += "+j" | ||
elif isinstance(justify, str): | ||
kwargs["F"] += f"+j{justify}" |
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.
if justify is True: | |
kwargs["F"] += "+j" | |
elif isinstance(justify, str): | |
kwargs["F"] += f"+j{justify}" | |
if justify: | |
kwargs["F"] += "+j" | |
if isinstance(justify, str): | |
kwargs["F"] += justify |
Co-authored-by: Wei Ji <[email protected]>
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.
…ngs (GenericMappingTools#1125) * Do not convert booleans in the kwargs_to_strings decorator * Deal with boolean values in build_arg_string * load_earth_relief no longer need the convert_bools=False hack * Fix the weird codes in subplot autolabel * Fix the weird codes in text Co-authored-by: Wei Ji <[email protected]>
Description of proposed changes
See #640 and #639 (the discussions and the fix) for context.
Changes in this PR:
convert_bools
parameter fromkwargs_to_strings
. Sokwargs_to_strings
won't convert boolean arguments.build_arg_string
function.use_srtm
parameter ofload_earth_relief
won't be converted to an empty string or removed anymore. Now it's safe to checkif use_strm
.autolabel
parameter ofsubplot
function can be either bool or str, but we had to check ifautolabel is not None
. It's not intuitive. Actually, we made a mistake in the initial version (4126c16) and then fixed it (eadb847).justify
,angle
, andfont
can be boolean, but we have to check if it'sNone
. This commit also fixes the weird codes.Fixes #640.
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version