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

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

Merged
merged 5 commits into from
Sep 26, 2021

Conversation

seisman
Copy link
Member

@seisman seisman commented Sep 24, 2021

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
Copy link
Member Author

seisman commented Sep 26, 2021

@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
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.

Copy link
Member

@michaelgrund michaelgrund left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Member

@weiji14 weiji14 left a comment

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?

pygmt/helpers/decorators.py Outdated Show resolved Hide resolved
@seisman
Copy link
Member Author

seisman commented Sep 26, 2021

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.

Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Copy link
Member

@weiji14 weiji14 left a comment

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
Copy link
Member Author

seisman commented Sep 27, 2021

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 <23487320+weiji14@users.noreply.github.com>
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