Skip to content

Add a decorator to raise a FutureWarning when positional arguments are passed for functions that changed parameter orders - #1541

Merged
seisman merged 5 commits into
mainfrom
check-table-input-order
Sep 26, 2021
Merged

seisman merged 5 commits into
mainfrom
check-table-input-order

Conversation

@seisman

@seisman seisman commented Sep 24, 2021 •

Copy link
Copy Markdown
Member

Description of proposed changes

See #1479 (comment) for discussions.

This PR adds a decorator to raise a warning when the order of parameters are changed and users are passing positional arguments.

Usage:

@fmt_docstring
@deprecate_parameter("sizes", "sizes", "v0.4.0", remove_version="v0.6.0")
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(...)
@kwargs_to_strings(...)
def plot(self, data=None, x=None, y=None, ....):
    pass

Address #1479.

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.

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

…e passed for functions that changed parameter orders
@seisman

seisman commented Sep 26, 2021 •

Copy link
Copy Markdown
Member Author

@GenericMappingTools/pygmt-maintainers Need to review/merge this PR before we can change the order of input parameters (e.g., #1547, #1546).

@michaelgrund

Copy link
Copy Markdown
Member

@GenericMappingTools/pygmt-maintainers Need to review/merge this PR before we can change the order of input parameters (e.g., #1547, #1546).

Sorry, totally overlooked this PR before opening #1547 and #1546.

@michaelgrund michaelgrund left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me!

@weiji14 weiji14 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I realize that this is a temporary decorator, which might not have much use after PyGMT v0.7.0, but should we:

  1. Add a usage note for @check_data_input_order at https://github.com/GenericMappingTools/pygmt/blob/main/doc/maintenance.md#backwards-compatibility-and-deprecation-policy
  2. Add a note in the docstring of this decorator function to say that this function can be removed after PyGMT v0.7.0?

Comment thread pygmt/helpers/decorators.py Resolved
@seisman

seisman commented Sep 26, 2021

Copy link
Copy Markdown
Member Author

I realize that this is a temporary decorator, which might not have much use after PyGMT v0.7.0, but should we:

  1. Add a usage note for @check_data_input_order at main/doc/maintenance.md#backwards-compatibility-and-deprecation-policy

I prefer not to add the usage, because it's likely that no one will use this decorator again after we finish issue #1479 (definitely before v0.5.0 release).

  1. Add a note in the docstring of this decorator function to say that this function can be removed after PyGMT v0.7.0?

Yes, it sounds good.

Comment thread pygmt/helpers/decorators.py Resolved

@weiji14 weiji14 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok to merge once you fix the lint issue. Some whitespace I think.

@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog final review call This PR requires final review and approval from a second reviewer labels Sep 26, 2021
@seisman seisman added this to the 0.5.0 milestone Sep 26, 2021
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Sep 26, 2021
@seisman
seisman merged commit b4a40dc into main Sep 26, 2021
@seisman
seisman deleted the check-table-input-order branch September 26, 2021 12:49
@seisman

seisman commented Sep 27, 2021 •

Copy link
Copy Markdown
Member Author

The decorator works well for non-plotting modules, but doesn't work for plotting modules (e.g., #1548, #1547), because for plotting modules, the first argument is self, thus, the length of the args array is at least 1.

Perhaps we have to check if the function is plotting or non-plotting.

sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…e passed for functions that changed parameter orders (GenericMappingTools#1541)

Co-authored-by: Wei Ji <[email protected]>

This branch was previously deployed

1 inactive deployment
Preview — a03c736d Deployed Sep 26, 2021 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants