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

Deprecate xshift (X) and yshift (Y) aliases from all plotting modules (remove in v0.12.0) #2071

Merged
merged 35 commits into from
Nov 21, 2022

Conversation

michaelgrund
Copy link
Member

@michaelgrund michaelgrund commented Aug 20, 2022

Description of proposed changes

This PR addresses #924 and removes the xshift (X) and yshift (Y) aliases from all plotting modules and gallery examples.

Modules:

  • Figure.basemap
  • Figure.coast
  • Figure.colorbar
  • Figure.contour
  • Figure.grdcontour
  • Figure.grdimage
  • Figure.grdview
  • Figure.histogram
  • Figure.image
  • Figure.legend
  • Figure.logo
  • Figure.meca
  • Figure.plot
  • Figure.plot3d
  • Figure.rose
  • Figure.solar
  • Figure.subplot
  • Figure.text
  • Figure.velo
  • Figure.wiggle

Gallery examples:

  • scatter3d.py

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

@michaelgrund michaelgrund added documentation Improvements or additions to documentation deprecation Deprecating a feature labels Aug 20, 2022
@michaelgrund michaelgrund added this to the 0.8.0 milestone Aug 20, 2022
@michaelgrund michaelgrund changed the title Remove xshift (X) and yshift (Y) aliases from all plotting modules WIP: Remove xshift (X) and yshift (Y) aliases from all plotting modules Aug 20, 2022
@michaelgrund michaelgrund marked this pull request as draft August 20, 2022 16:21
@michaelgrund
Copy link
Member Author

Should we add the warning/error if xshift, yshift, X or Y are passed directly into each function or create a correspondig decorator @GenericMappingTools/pygmt-maintainers? Exemplary I added one in basemap.py.

@michaelgrund michaelgrund requested review from willschlitzer, seisman and weiji14 and removed request for willschlitzer and seisman August 20, 2022 17:04
@seisman
Copy link
Member

seisman commented Aug 21, 2022

Should we add the warning/error if xshift, yshift, X or Y are passed directly into each function or create a correspondig decorator @GenericMappingTools/pygmt-maintainers? Exemplary I added one in basemap.py.

I feel it's possible to add the warning in the use_alias decorator, instead of creating a new decorator.

@michaelgrund
Copy link
Member Author

Should we add the warning/error if xshift, yshift, X or Y are passed directly into each function or create a correspondig decorator @GenericMappingTools/pygmt-maintainers? Exemplary I added one in basemap.py.

I feel it's possible to add the warning in the use_alias decorator, instead of creating a new decorator.

I updated the use_alias decorator. Is this the direction you had in mind @seisman?

@seisman
Copy link
Member

seisman commented Aug 21, 2022

Should we add the warning/error if xshift, yshift, X or Y are passed directly into each function or create a correspondig decorator @GenericMappingTools/pygmt-maintainers? Exemplary I added one in basemap.py.

I feel it's possible to add the warning in the use_alias decorator, instead of creating a new decorator.

I updated the use_alias decorator. Is this the direction you had in mind @seisman?

Yes. Does it work as expected?

@@ -574,6 +565,14 @@ def new_module(*args, **kwargs):
f"Parameters in short-form ({short_param}) and "
f"long-form ({long_alias}) can't coexist."
)
if (long_alias in kwargs and long_alias in ["xshift", "yshift"]) or (
Copy link
Member

Choose a reason for hiding this comment

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

I think it doesn't works, because after removing X="xshift" and Y="yshift" from the use_alias decorator, the variable aliases at line 571 no longer contain the paramters xshift or yshift.

Instead, after line 583, you can check if any of xshift, yshift, X and Y exists in kwargs. If yes, then raise an warning. For backward compatibility, you also need to do the "xshift"->X and "yshift"->"Y" conversions if "xshift" or "yshift" is used.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, you mean to leave X="xshift" and Y="yshift" as is in each function and add the others at this point, too @seisman ?

@use_alias(
    X="xshift",
    Y="yshift",
    xshift="X",
    yshift="Y",
)

Copy link
Member

Choose a reason for hiding this comment

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

So, you mean to leave X="xshift" and Y="yshift" as is in each function and add the others at this point, too @seisman ?

@use_alias(
    X="xshift",
    Y="yshift",
    xshift="X",
    yshift="Y",
)

No. Changes to other files (e.g., basemap.py) make sense to me. The only thing that is missing is how to correctly check if users use xshift, yshift, X or Y. The checking should be done in the pygmt/helpers/decorators.py file.

Comment on lines 571 to 575
raise GMTInvalidInput(
f"Parameters ({short_param}) and "
f"({long_alias}) are not supported anymore."
f" Please use shift_origin() instead!"
)
Copy link
Member

Choose a reason for hiding this comment

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

Using an error here will immediately break people's code if they're using xshift or yshift. Better to go through a deprecation cycle that raises a FutureWarning instead.

One idea is to use the @deprecate_parameter function and do something like @deprecate_parameter(oldname="xshift", newname=None, deprecate_version="v0.8.0", remove_version="0.10.0"). This will require some modifications to the decorator to handle newname=None though.

Copy link
Member

Choose a reason for hiding this comment

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

One idea is to use the @deprecate_parameter function and do something like @deprecate_parameter(oldname="xshift", newname=None, deprecate_version="v0.8.0", remove_version="0.10.0"). This will require some modifications to the decorator to handle newname=None though.

We don't have to use @deprecate_parameter for this, which requires adding @deprecate_parameter decorators in many Python files.

Copy link
Member Author

Choose a reason for hiding this comment

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

I modified the passage @seisman. I understand the concerns @weiji14 has regarding raising an error here. However, we did agree to totally drop this option (not only deprecate it), didn't we?

Copy link
Member

Choose a reason for hiding this comment

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

Looking at #924 (comment), I think the intention was to remove xshift/yshift from the docstring, not completely from the code. I.e. the aliases should still work (with a FutureWarning) for at least 2 more minor versions. But maybe I'm missing some context here, was there a discussion to drop xshift/yshift in a backward incompatible way?

Copy link
Member

Choose a reason for hiding this comment

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

was there a discussion to drop xshift/yshift in a backward incompatible way?

No, we definitely need backward compatibility.

The final goal is, for the next 2 or more minor versions, users can still use parameters xshift, yshift, X, Y, and they will see a FutureWarning like:

Parameters xshift, yshift, X and Y are deprecated and will be no longer 
supported in v0.x.x. Please user Figure.shift_origin() instead.

One idea is to use the @deprecate_parameter function and do something like @deprecate_parameter(oldname="xshift", newname=None, deprecate_version="v0.8.0", remove_version="0.10.0"). This will require some modifications to the decorator to handle newname=None though.

I believe this will work but it's not ideal. It's easy to modify the deprecate_parameter decorator to support newname=None, but the warning message would be something like:

The 'xxxx' parameter has been deprecated since vx.x.x and will be removed in vx.x.x.

The error message can't recommend using Figure.shift_origin() unless we deal with xshift and yshfit in a special way.

It's also more confusing when users use the short parameters X or Y. When they use X, they are recommended to use xshift. After they modify X to xshift, then they see xshfit is deprecated.

Copy link
Member

@seisman seisman Sep 24, 2022

Choose a reason for hiding this comment

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

I've opened PR #2135, which shows how we can deprecate timestamp (U) in a backward-compatible way and recommend Figure.timestamp() (not implemented yet) instead. The same idea can be applied to xshift and yshift in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I applied your implemetations for this PR @seisman.

@michaelgrund
Copy link
Member Author

/format

@michaelgrund
Copy link
Member Author

/format

@michaelgrund
Copy link
Member Author

Some changes need to be made:

Added 4 tests covering each parameter. Do we need all 4 or is one sufficient @seisman ?

@seisman
Copy link
Member

seisman commented Nov 16, 2022

Some changes need to be made:

Added 4 tests covering each parameter. Do we need all 4 or is one sufficient @seisman ?

I think we can merge the four tests into one larger test.

Comment on lines 290 to 298
def test_figure_depr_x():
"""
Check if deprecation of X parameter works correctly if used.
"""
fig = Figure()
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
with pytest.warns(expected_warning=SyntaxWarning) as record:
fig.plot(x=1, y=1, style="c3c", X="3c")
assert len(record) == 1 # check that only one warning was raised
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the testing of X and Y needs to be included if xshift and yshift are already included, since we trust that the aliases translate to the appropriate arguments?

Copy link
Member

Choose a reason for hiding this comment

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

Does the testing of X and Y needs to be included if xshift and yshift are already included, since we trust that the aliases translate to the appropriate arguments?

I think we still need to test X and Y, because we have removed the "X=>xshift" and "Y=>yshift" aliases in this PR.

pygmt/tests/test_figure.py Outdated Show resolved Hide resolved
michaelgrund and others added 2 commits November 19, 2022 10:57
@seisman
Copy link
Member

seisman commented Nov 19, 2022

/format

@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed documentation Improvements or additions to documentation labels Nov 19, 2022
@seisman
Copy link
Member

seisman commented Nov 20, 2022

Ping @GenericMappingTools/pygmt-maintainers for final reviews.

Copy link
Contributor

@willschlitzer willschlitzer left a comment

Choose a reason for hiding this comment

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

Nice work @michaelgrund!

@seisman seisman merged commit 91bfe28 into main Nov 21, 2022
@seisman seisman deleted the remove-x-y-shift branch November 21, 2022 15:19
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Nov 21, 2022
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
… (remove in v0.12.0) (GenericMappingTools#2071)

Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
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.

5 participants