You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Decorator kwargs_to_strings can deal with boolean arguments. For example, dict {'A': True, 'B': False, 'R': '0/10/0/10'} will be converted to {'A': '', 'R': '0/10/0/10'} first, and then build_arg_strings will further convert it to valid GMT arguments -A -R0/10/0/10.
The decorator works well for arguments that will be passed to GMT, but doesn't work for pure Python arguments.
Full code that generated the error
frompprintimportpprintfrompygmt.helpers.decoratorsimportkwargs_to_strings@kwargs_to_strings(R='sequence', files='sequence_space')defmodule(nongmt_args=True, *args, **kwargs):
"A module that prints the arguments it received"pprint(args)
pprint(kwargs)
ifnongmt_argsisTrue:
print("nongmt_args is still True. Do something in PyGMT.")
elifnongmt_args=="":
print("the kwargs_to_strings decorator converts nongmt_args to an empty string.")
else:
print(f"nongmt_args is '{nongmt_args}'")
module(R=[1, 2, 3, 4], nongmt_args=True)
Output
()
{'R': '1/2/3/4'}
the kwargs_to_strings decorator converts nongmt_args to an empty string.
As shown in the output above, the boolean argument nongmt_args is converted from True to an empty string "". Thus, checking nongmt_args is True no longer works.
If removing the kwargs_to_strings decorator before the module function, the output is:
()
{'R': [1, 2, 3, 4]}
nongmt_args is still True. Do something in PyGMT.
Possible solution
Like what we do in #639, the possible solution is to convert boolean arguments in build_arg_strings function before passing arguments to GMT, not in the kwargs_to_strings decorator.
System information
Please paste the output of python -c "import pygmt; pygmt.show_versions()":
Description of the problem
pygmt/pygmt/helpers/decorators.py
Line 279 in c191d3e
Decorator
kwargs_to_strings
can deal with boolean arguments. For example, dict{'A': True, 'B': False, 'R': '0/10/0/10'}
will be converted to{'A': '', 'R': '0/10/0/10'}
first, and thenbuild_arg_strings
will further convert it to valid GMT arguments-A -R0/10/0/10
.The decorator works well for arguments that will be passed to GMT, but doesn't work for pure Python arguments.
Full code that generated the error
Output
As shown in the output above, the boolean argument
nongmt_args
is converted fromTrue
to an empty string""
. Thus, checkingnongmt_args is True
no longer works.If removing the
kwargs_to_strings
decorator before themodule
function, the output is:Possible solution
Like what we do in #639, the possible solution is to convert boolean arguments in
build_arg_strings
function before passing arguments to GMT, not in thekwargs_to_strings
decorator.System information
Please paste the output of
python -c "import pygmt; pygmt.show_versions()"
:The text was updated successfully, but these errors were encountered: