-
Notifications
You must be signed in to change notification settings - Fork 235
Disallow passing arguments like -XNone to GMT #639
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
|
@MarkWieczorek Please see if this PR works for you. |
| elif kwargs[key] is None: # arguments like -XNone are invalid | ||
| continue |
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.
So X=None should return the same result as X=False, following what was suggested at #380 (comment).
Question is, should the None detection logic be placed here, or would it be better to put it in remove_bools somewhere here:
pygmt/pygmt/helpers/decorators.py
Lines 436 to 443 in 1bf0a30
| new_kwargs = {} | |
| for arg, value in kwargs.items(): | |
| if isinstance(value, bool): | |
| if value: | |
| new_kwargs[arg] = "" | |
| else: | |
| new_kwargs[arg] = value | |
| return new_kwargs |
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.
#640 explains why we can't deal with None or even boolean values in the kwargs_to_strings decorator.
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.
This is very confusing 😕, so for most PyGMT modules, we go through 1) kwargs_to_strings decorator, 2) some PyGMT virtualfile logic or whatever, and then 3) the build_arg_string which passes things to GMT C API.
In (1), the kwargs_to_string has a remove_bools setting that turns True into an empty string "", are you suggesting in #640 that we should not perform that True to "" conversion in (1), but move it to (3) at build_arg_string instead? Similarly in this PR, None has to be handled later at step (3) in build_arg_string, rather than at step (1) in kwargs_to_string/remove_bools.
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.
Yes, as shown in #640, the boolean argument nongmt_args should be True or False. However, when calling the function, the decorator kwargs_to_string converts nongmt_args=True to nongmt_args="". It makes sense if nongmt_args is an alias of GMT options (e.g., -N), so that we can pass -N to GMT. However, when nongmt_args is just a Python variable, the conversion means checking nongmt_args is True or False won't work.
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.
BTW, I just updated the codes in #640, hopefully, to make the issue easier to understand.
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.
So reading #640, does that mean that True/False inputs will eventually need to go here in build_arg_strings as well? It seems weird to have both kwargs_to_strings and build_arg_strings handling different pieces of Python to GMT logic.
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.
does that mean that
True/Falseinputs will eventually need to go here inbuild_arg_stringsas well?
Yes.
It seems weird to have both
kwargs_to_stringsandbuild_arg_stringshandling different pieces of Python to GMT logic.
Yes, as mentioned in #640, handling boolean arguments in kwargs_to_strings is incorrect, and we should fix #640 by moving the True/False conversion to build_arg_strings (but in a separate PR).
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, this PR should be fine then for now. I'll approve it but you'll need to update the branch in order to merge.
| elif kwargs[key] is None: # arguments like -XNone are invalid | ||
| continue |
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, this PR should be fine then for now. I'll approve it but you'll need to update the branch in order to merge.
Description of proposed changes
Arguments like
-XNoneare invalid for GMT.This PR updates the function
build_arg_stringand checks if any value isNone.If yes, remove the argument.
Limitations:
Invalid arguments like
{'X': [None, None, None]}are still not caught andconverted to
-XNone -XNone -XNone, but it should be uncommon and more likelya user error.
Fixes #380.
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.