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

Figure.plot: Deprecate parameter "columns" to "incols" (remove in v0.6.0) #1298

Merged
merged 7 commits into from
May 28, 2021

Conversation

michaelgrund
Copy link
Member

@michaelgrund michaelgrund commented May 26, 2021

Description of proposed changes

As discussed in #764, this PR replaces the columns parameter by incols for Figure.plot().

  • Rename the parameter columns to incols in Figure.plot()
  • Updates tests and examples to use the new parameter name
  • Use the deprecate_parameter decorator for backward-compatibility
  • Add a test for checking 'columns' backward compatibility

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.
  • Write detailed docstrings for all functions/methods.

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

…6.0)

As discussed in #764, this PR replaces the **columns** parameter by **incols** for plot.py and adds the deprecation .
@michaelgrund michaelgrund added the deprecation Deprecating a feature label May 26, 2021
@michaelgrund michaelgrund added this to the 0.4.0 milestone May 26, 2021
@michaelgrund michaelgrund linked an issue May 26, 2021 that may be closed by this pull request
@michaelgrund michaelgrund marked this pull request as draft May 26, 2021 06:46
@maxrjones
Copy link
Member

The alias name and description for incols should go in COMMON_OPTIONS in decorators.py. I will submit a separate PR for adding the incols common option to decorators.py so that it does not get complicated coordinating the timing of this PR and #1040.

@michaelgrund
Copy link
Member Author

The alias name and description for incols should go in COMMON_OPTIONS in decorators.py. I will submit a separate PR for adding the incols common option to decorators.py so that it does not get complicated coordinating the timing of this PR and #1040.

Sounds great!

@michaelgrund
Copy link
Member Author

Any idea why the newly added test fails here @seisman ?

@seisman
Copy link
Member

seisman commented May 26, 2021

Any idea why the newly added test fails here @seisman ?

I think I misunderstood the order Python executes decorators. I thought the execution order is bottom-to-top, but the actual execution order is top-to-bottom (see https://gist.github.com/kirsle/bf24622fc5f255256c6e for detailed explanations).

If the top-to-bottom execution order is correct, the deprecate_parameter decorator should always be put before the use_alias decorator.

Edit: After trying the examples in https://gist.github.com/kirsle/bf24622fc5f255256c6e and https://stackoverflow.com/questions/27342149/, I'm more confused about the order. The former example supports top-to-bottom order, but the latter example supports bottom-to-top order. Am I still misunderstanding it?

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.

Python decorators are applied top-down according to https://realpython.com/primer-on-python-decorators/#nesting-decorators. The implementation of @deprecate_parameter is correct-ish, but we need to move the @deprecate_parameter decorator to be after @fmt_docstring and before @use_alias.

Comment on lines 47 to 48
@deprecate_parameter("sizes", "size", "v0.4.0", remove_version="v0.6.0")
@deprecate_parameter("columns", "incols", "v0.4.0", remove_version="v0.6.0")
Copy link
Member

@weiji14 weiji14 May 26, 2021

Choose a reason for hiding this comment

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

The problem is that test_plot_deprecate_columns_to_incols uses a list instead of str for the columns parameter. The correct order should be:

  1. Rename 'columns' to 'incols' via @deprecate_parameter
  2. Convert long alias 'incols' to GMT short alias 'i' via @use_alias
  3. Let the list type argument [0, 1] be converted to str type 0,1 via @kwargs_to_strings
  4. Pass in -i0,1 to lib.call_module("plot", ...)

So you'll need to move these 2 @deprecate_parameter lines to between L17 and L18.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your replies and the clarification @seisman and @weiji14.

@michaelgrund michaelgrund self-assigned this May 27, 2021
@michaelgrund
Copy link
Member Author

The alias name and description for incols should go in COMMON_OPTIONS in decorators.py. I will submit a separate PR for adding the incols common option to decorators.py so that it does not get complicated coordinating the timing of this PR and #1040.

Now the description for incols from COMMON_OPTIONS is used.

@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label May 27, 2021
@michaelgrund michaelgrund changed the title WIP: Figure.plot: Deprecate parameter "columns" to "incols" (remove in v0.6.0) Figure.plot: Deprecate parameter "columns" to "incols" (remove in v0.6.0) May 27, 2021
@michaelgrund michaelgrund marked this pull request as ready for review May 27, 2021 15:32
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label May 28, 2021
@seisman seisman merged commit ec73ea4 into master May 28, 2021
@seisman seisman deleted the plot-depr-columns branch May 28, 2021 07:33
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…6.0) (GenericMappingTools#1298)

* Figure.plot: Deprecate parameter "columns" to "incols" (remove in v0.6.0)
* add new test
* add shortcut to use incols description from COMMON_OPTIONS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation Deprecating a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Description for the "columns" arguments is missing
4 participants