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

None shall not pass args_in_kwargs #1815

Merged
merged 7 commits into from
Apr 3, 2022
Merged

None shall not pass args_in_kwargs #1815

merged 7 commits into from
Apr 3, 2022

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Mar 14, 2022

Description of proposed changes

Fixes bug in args_in_kwargs function whereby None values are allowed, when actually, we want to drop the None. Specifically, this would fix potential bugs in basemap, coast and grdgradient.

This kwargs.get(arg) idea is actually adapted from #731 (comment).

Fixes #1665

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 wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

Fixes bug in `args_in_kwargs` function whereby `None` values
are allowed, when actually, we want to drop the `None`.
@weiji14 weiji14 added the bug Something isn't working label Mar 14, 2022
@weiji14 weiji14 added this to the 0.6.1 milestone Mar 14, 2022
@weiji14 weiji14 self-assigned this Mar 14, 2022
pygmt/tests/test_figure.py Outdated Show resolved Hide resolved
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to modify this one-liner return statement so that args_in_kwargs(args=["A", "B"], kwargs={"B": 0}) returns True.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we should change it to:

return any(kwargs.get(arg) is not None for arg in args)

right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

pygmt/tests/test_figure.py Outdated Show resolved Hide resolved
"""
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@weiji14 weiji14 added the final review call This PR requires final review and approval from a second reviewer label Apr 1, 2022
@weiji14 weiji14 marked this pull request as ready for review April 3, 2022 13:56
@weiji14 weiji14 enabled auto-merge (squash) April 3, 2022 13:58
@weiji14 weiji14 merged commit 4cfe813 into main Apr 3, 2022
@weiji14 weiji14 deleted the fix/None_kwargs branch April 3, 2022 14:11
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Apr 3, 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
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
None yet
Development

Successfully merging this pull request may close these issues.

Setting frame=None gives unexpected results
2 participants