Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,13 @@ def new_module(*args, **kwargs):
)
warnings.warn(msg, category=SyntaxWarning, stacklevel=2)

# timestamp (U) is deprecated since v0.9.0.
Copy link
Member

Choose a reason for hiding this comment

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

After this PR, the expected behaviors are:

  • if timestamp=True is used, Python will report the parameter is not recognized
  • if single-letter parameter U=True is used, PyGMT should tell users that U is not supported and Figure.timestamp should be used.

After removing lines 570-580, parameter timestamp is no longer recognized, but single-letter parameter U will still be processed. Thus, instead of removing these lines completely, we should change them to something like:

            # timestamp (U)is deprecated since v0.9.0.
            if "U" in kwargs:
                msg = (
                    "Parameter timestamp/U is no longer supported since v0.12.0."
                    "Use Figure.timestamp() instead."
                )
                raise GMTInvalidInput(msg)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, OK. Thanks! I have tried to change this in the commits 6977a57, 1501ccc, and 42fab3b. I also changed this in PR #3044 for xshift (X) and yshift (Y).

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

# xshift (X) is deprecated since v0.8.0.
if "X" in kwargs or "xshift" in kwargs:
Expand Down
41 changes: 11 additions & 30 deletions pygmt/tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Test Figure.timestamp.
"""
import pytest
from pygmt import Figure, config
from pygmt import Figure
from pygmt.exceptions import GMTInvalidInput


@pytest.fixture(scope="module", name="faketime")
Expand Down Expand Up @@ -95,36 +96,16 @@ def test_timestamp_text_truncated():
return fig


@pytest.mark.mpl_image_compare(filename="test_timestamp.png")
def test_timestamp_deprecated_timestamp(faketime):
"""
Check if the deprecated parameter 'timestamp' works but raises a warning.
def test_timestamp_unsupported_u_timestamp():
"""
fig = Figure()
with pytest.warns(expected_warning=SyntaxWarning) as record:
with config(FORMAT_TIME_STAMP=faketime):
# plot nothing (the data is outside the region) but a timestamp
fig.plot(
x=0,
y=0,
style="p",
projection="X1c",
region=[1, 2, 1, 2],
timestamp=True,
)
assert len(record) == 1 # check that only one warning was raised
return fig
Raise an exception when either U or timestamp is used.


@pytest.mark.mpl_image_compare(filename="test_timestamp.png")
def test_timestamp_deprecated_u(faketime):
"""
Check if the deprecated parameter 'U' works but raises a warning.
Parameters U and timestamp are no longer supported since v0.12.0.
"""
fig = Figure()
with pytest.warns(expected_warning=SyntaxWarning) as record:
with config(FORMAT_TIME_STAMP=faketime):
# plot nothing (the data is outside the region) but a timestamp
fig.plot(x=0, y=0, style="p", projection="X1c", region=[1, 2, 1, 2], U=True)
assert len(record) == 1 # check that only one warning was raised
return fig
with pytest.raises(GMTInvalidInput):
fig.plot(x=0, y=0, style="p", projection="X1c", region=[1, 2, 1, 2], U=True)
with pytest.raises(GMTInvalidInput):
fig.plot(
x=0, y=0, style="p", projection="X1c", region=[1, 2, 1, 2], timestamp=True
)