-
Notifications
You must be signed in to change notification settings - Fork 224
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
Conversation
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 |
I updated the |
Yes. Does it work as expected? |
pygmt/helpers/decorators.py
Outdated
@@ -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 ( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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",
)
There was a problem hiding this comment.
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.
pygmt/helpers/decorators.py
Outdated
raise GMTInvalidInput( | ||
f"Parameters ({short_param}) and " | ||
f"({long_alias}) are not supported anymore." | ||
f" Please use shift_origin() instead!" | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 handlenewname=None
though.
We don't have to use @deprecate_parameter
for this, which requires adding @deprecate_parameter
decorators in many Python files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 handlenewname=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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
/format |
/format |
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. |
pygmt/tests/test_figure.py
Outdated
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
andY
needs to be included ifxshift
andyshift
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.
Co-authored-by: Dongdong Tian <[email protected]>
/format |
Ping @GenericMappingTools/pygmt-maintainers for final reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @michaelgrund!
… (remove in v0.12.0) (GenericMappingTools#2071) Co-authored-by: Dongdong Tian <[email protected]>
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:
Gallery examples:
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version