From ea046d22bab1d9b2964d6ef3f1b3b0a486f40efa Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 22 Nov 2023 21:12:07 +0800 Subject: [PATCH] Use the improved kwargs_to_strings decorator --- pygmt/src/timestamp.py | 12 +++++------- pygmt/src/which.py | 6 ++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pygmt/src/timestamp.py b/pygmt/src/timestamp.py index 1fe65c1bc4e..e959523e2ae 100644 --- a/pygmt/src/timestamp.py +++ b/pygmt/src/timestamp.py @@ -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, @@ -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. diff --git a/pygmt/src/which.py b/pygmt/src/which.py index 3fdcafa91f5..d20059f0492 100644 --- a/pygmt/src/which.py +++ b/pygmt/src/which.py @@ -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. @@ -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(