Skip to content
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

Disallow passing arguments like -XNone to GMT #639

Merged
merged 4 commits into from
Oct 8, 2020
Merged

Conversation

seisman
Copy link
Member

@seisman seisman commented Oct 4, 2020

Description of proposed changes

Arguments like -XNone are invalid for GMT.

This PR updates the function build_arg_string and checks if any value is None.
If yes, remove the argument.

Limitations:

Invalid arguments like {'X': [None, None, None]} are still not caught and
converted to -XNone -XNone -XNone, but it should be uncommon and more likely
a user error.

Fixes #380.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

@seisman seisman added the bug Something isn't working label Oct 4, 2020
@seisman seisman added this to In progress in Release v0.2.x via automation Oct 4, 2020
@seisman seisman added this to the 0.2.1 milestone Oct 4, 2020
@seisman seisman requested a review from weiji14 October 4, 2020 06:12
@seisman
Copy link
Member Author

seisman commented Oct 4, 2020

@MarkWieczorek Please see if this PR works for you.

Comment on lines +154 to +155
elif kwargs[key] is None: # arguments like -XNone are invalid
continue
Copy link
Member

@weiji14 weiji14 Oct 5, 2020

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:

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

Copy link
Member Author

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.

Copy link
Member

@weiji14 weiji14 Oct 5, 2020

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.

Copy link
Member Author

@seisman seisman Oct 5, 2020

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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/False inputs will eventually need to go here in build_arg_strings as well?

Yes.

It seems weird to have both kwargs_to_strings and build_arg_strings handling 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).

Copy link
Member

@weiji14 weiji14 Oct 8, 2020

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.

Comment on lines +154 to +155
elif kwargs[key] is None: # arguments like -XNone are invalid
continue
Copy link
Member

@weiji14 weiji14 Oct 8, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Offsets "X" and "Y" provide unexpected results when provided
2 participants