Skip to content
Merged
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")


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