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 "timestamp" ("U") parameter, use "Figure.timestamp" instead (deprecated since v0.9.0) #3045

Merged
merged 15 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
7 changes: 2 additions & 5 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,11 @@ def new_module(*args, **kwargs):

# 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).

seisman marked this conversation as resolved.
Show resolved Hide resolved
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
seisman marked this conversation as resolved.
Show resolved Hide resolved


@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
)
Loading