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: Remove deprecated "xshift" ("X") and "yshift" ("Y") parameters, use "Figure.shift_origin" instead (deprecated since v0.8.0) #3044

Merged
merged 11 commits into from
Feb 28, 2024
18 changes: 6 additions & 12 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,27 +578,21 @@ def new_module(*args, **kwargs):
)
warnings.warn(msg, category=SyntaxWarning, stacklevel=2)

# xshift (X) is deprecated since v0.8.0.
# xshift (X) is deprecated since v0.8.0 and removed in v0.12.0.
if "X" in kwargs or "xshift" in kwargs:
if "xshift" in kwargs:
kwargs["X"] = kwargs.pop("xshift")
msg = (
"Parameters 'X' and 'xshift' are deprecated since v0.8.0 "
"and will be removed in v0.12.0. "
"Parameters 'X' and 'xshift' are no longer supported since v0.12.0. "
"Use Figure.shift_origin(xshift=...) instead."
)
warnings.warn(msg, category=SyntaxWarning, stacklevel=2)
raise GMTInvalidInput(msg)

# yshift (Y) is deprecated since v0.8.0.
# yshift (Y) is deprecated since v0.8.0 and removed in v0.12.0.
if "Y" in kwargs or "yshift" in kwargs:
if "yshift" in kwargs:
kwargs["Y"] = kwargs.pop("yshift")
msg = (
"Parameters 'Y' and 'yshift' are deprecated since v0.8.0. "
"and will be removed in v0.12.0. "
"Parameters 'Y' and 'yshift' are no longer supported since v0.12.0. "
"Use Figure.shift_origin(yshift=...) instead."
)
warnings.warn(msg, category=SyntaxWarning, stacklevel=2)
raise GMTInvalidInput(msg)

return module_func(*args, **kwargs)

Expand Down
16 changes: 6 additions & 10 deletions pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,17 @@ def test_figure_set_display_invalid():
set_display(method="invalid")
seisman marked this conversation as resolved.
Show resolved Hide resolved


def test_figure_deprecated_xshift_yshift():
def test_figure_unsupported_xshift_yshift():
"""
Check if deprecation of parameters X/Y/xshift/yshift work correctly if used.
Raise an exception if X/Y/xshift/yshift is used.
"""
fig = Figure()
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
with pytest.warns(expected_warning=SyntaxWarning) as record:
with pytest.raises(GMTInvalidInput):
fig.plot(x=1, y=1, style="c3c", xshift="3c")
assert len(record) == 1 # check that only one warning was raised
with pytest.warns(expected_warning=SyntaxWarning) as record:
with pytest.raises(GMTInvalidInput):
fig.plot(x=1, y=1, style="c3c", X="3c")
assert len(record) == 1 # check that only one warning was raised
with pytest.warns(expected_warning=SyntaxWarning) as record:
with pytest.raises(GMTInvalidInput):
fig.plot(x=1, y=1, style="c3c", yshift="3c")
assert len(record) == 1 # check that only one warning was raised
with pytest.warns(expected_warning=SyntaxWarning) as record:
with pytest.raises(GMTInvalidInput):
fig.plot(x=1, y=1, style="c3c", Y="3c")
assert len(record) == 1 # check that only one warning was raised
Loading