Conversation
Fixes bug in `args_in_kwargs` function whereby `None` values are allowed, when actually, we want to drop the `None`.
weiji14
commented
Mar 14, 2022
pygmt/helpers/utils.py
Outdated
Comment on lines
323
to
326
| >>> args_in_kwargs(args=["A", "B"], kwargs={"B": 0}) | ||
| True | ||
| """ | ||
| return any(arg in kwargs for arg in args) | ||
| return any(kwargs.get(arg) for arg in args) |
Member
Author
There was a problem hiding this comment.
Need to modify this one-liner return statement so that args_in_kwargs(args=["A", "B"], kwargs={"B": 0}) returns True.
Member
There was a problem hiding this comment.
So, we should change it to:
return any(kwargs.get(arg) is not None for arg in args)
right?
Member
Author
There was a problem hiding this comment.
Close. I had to do return any(kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args) so that arguments that are False don't count. Done in 7c3c6b4
seisman
reviewed
Apr 1, 2022
seisman
reviewed
Apr 1, 2022
| """ | ||
| return any(arg in kwargs for arg in args) | ||
| return any( | ||
| kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args |
Member
There was a problem hiding this comment.
Is the following code better?
Suggested change
| kwargs.get(arg) is not None and kwargs.get(arg) is not False for arg in args | |
| kwargs.get(arg) not in (None, False) for arg in args |
Member
Author
There was a problem hiding this comment.
This doesn't work, need to use is instead of in or == to do the check against None or False:
323 >>> args_in_kwargs(args=["A", "B"], kwargs={"B": 0})
Expected:
True
Got:
False
This reverts commit a9831f3.
seisman
approved these changes
Apr 1, 2022
sixy6e
pushed a commit
to sixy6e/pygmt
that referenced
this pull request
Dec 21, 2022
Fixes bug in `args_in_kwargs` function whereby `None` values are allowed, when actually, we want to drop the `None`. * Add failing test for when param=0 * Check that argument is not None or False
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
Fixes bug in
args_in_kwargsfunction wherebyNonevalues are allowed, when actually, we want to drop theNone. Specifically, this would fix potential bugs inbasemap,coastandgrdgradient.This
kwargs.get(arg)idea is actually adapted from #731 (comment).Fixes #1665
Reminders
make formatandmake checkto 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