Skip to content

Commit 16f2ef5

Browse files
committed
Use the sequence_join function
1 parent 2db06b2 commit 16f2ef5

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pygmt/alias.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from collections.abc import Mapping
88
from typing import Any, Literal
99

10-
from pygmt.helpers.utils import is_nonstr_iter
10+
from pygmt.helpers.utils import is_nonstr_iter, sequence_join
1111

1212

1313
def to_string(
1414
value: Any,
1515
prefix: str = "", # Default to an empty string to simplify the code logic.
16-
separator: Literal["/", ","] | None = None,
1716
mapping: bool | Mapping = False,
17+
separator: Literal["/", ","] | None = None,
1818
) -> str | list[str] | None:
1919
"""
2020
Convert any value to a string, a sequence of strings or None.
@@ -48,11 +48,11 @@ def to_string(
4848
The value to convert.
4949
prefix
5050
The string to add as a prefix to the returned value.
51-
separator
52-
The separator to use if the value is a sequence.
5351
mapping
5452
A mapping dictionary or ``True`` to map long-form arguments to GMT's short-form
5553
arguments. If ``True``, will use the first letter of the long-form arguments.
54+
separator
55+
The separator to use if the value is a sequence.
5656
5757
Returns
5858
-------
@@ -97,12 +97,14 @@ def to_string(
9797
value = value[0] if mapping is True else mapping.get(value, value)
9898
return f"{prefix}{value}"
9999

100-
# Convert a sequence of values to a sequence of strings.
101-
# In some cases, "prefix" and "mapping" are ignored. We can enable them when needed.
102-
_values = [str(item) for item in value]
103-
# When separator is not specified, return a sequence of strings for repeatable GMT
104-
# options like '-B'. Otherwise, join the sequence of strings with the separator.
105-
return _values if separator is None else f"{prefix}{separator.join(_values)}"
100+
# Return the sequence if separator is not specified for options like '-B'.
101+
if separator is None:
102+
return value
103+
104+
# Join the sequence of values with the separator.
105+
# "prefix" and "mapping" are ignored. We can enable them when needed.
106+
_value = sequence_join(value, separator=separator)
107+
return f"{prefix}{_value}"
106108

107109

108110
@dataclasses.dataclass

pygmt/src/coast.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
kwargs_to_strings,
1515
use_alias,
1616
)
17-
from pygmt.src._common import _parse_coastline_resolution
1817

1918
__doctest_skip__ = ["coast"]
2019

0 commit comments

Comments
 (0)