Skip to content

Commit

Permalink
Use the improved kwargs_to_strings decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Nov 22, 2023
1 parent f53e5d7 commit ea046d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 5 additions & 7 deletions pygmt/src/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from packaging.version import Version
from pygmt.clib import Session, __gmt_version__
from pygmt.helpers import build_arg_string, is_nonstr_iter
from pygmt.helpers import build_arg_string, kwargs_to_strings

__doctest_skip__ = ["timestamp"]


@kwargs_to_strings(offset="sequence")
def timestamp(
self,
text=None,
Expand Down Expand Up @@ -83,14 +84,11 @@ def timestamp(
kwdict["U"] += f"{label}"
kwdict["U"] += f"+j{justification}"

if is_nonstr_iter(offset): # given a tuple
kwdict["U"] += "+o" + "/".join(f"{item}" for item in offset)
elif "/" not in offset and Version(__gmt_version__) <= Version("6.4.0"):
if "/" not in offset and Version(__gmt_version__) <= Version("6.4.0"):
# Giving a single offset doesn't work in GMT <= 6.4.0.
# See https://github.com/GenericMappingTools/gmt/issues/7107.
kwdict["U"] += f"+o{offset}/{offset}"
else:
kwdict["U"] += f"+o{offset}"
offset = f"{offset}/{offset}"
kwdict["U"] += f"+o{offset}"

# The +t modifier was added in GMT 6.5.0.
# See https://github.com/GenericMappingTools/gmt/pull/7127.
Expand Down
6 changes: 2 additions & 4 deletions pygmt/src/which.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
GMTTempFile,
build_arg_string,
fmt_docstring,
is_nonstr_iter,
kwargs_to_strings,
use_alias,
)


@fmt_docstring
@use_alias(G="download", V="verbose")
@kwargs_to_strings(fname="sequence_space")
def which(fname, **kwargs):
r"""
Find the full path to specified files.
Expand Down Expand Up @@ -62,9 +63,6 @@ def which(fname, **kwargs):
FileNotFoundError
If the file is not found.
"""
if is_nonstr_iter(fname): # Got a list of files
fname = " ".join(fname)

with GMTTempFile() as tmpfile:
with Session() as lib:
lib.call_module(
Expand Down

0 comments on commit ea046d2

Please sign in to comment.