|
7 | 7 | from pygmt.helpers import (
|
8 | 8 | build_arg_string,
|
9 | 9 | data_kind,
|
10 |
| - dummy_context, |
11 | 10 | fmt_docstring,
|
12 | 11 | is_nonstr_iter,
|
13 | 12 | kwargs_to_strings,
|
@@ -157,15 +156,19 @@ def text_(
|
157 | 156 | # Ensure inputs are either textfiles, x/y/text, or position/text
|
158 | 157 | if position is None:
|
159 | 158 | kind = data_kind(textfiles, x, y, text)
|
| 159 | + if kind == "vectors" and text is None: |
| 160 | + raise GMTInvalidInput("Must provide text with x/y pairs") |
| 161 | + if kind == "file" and text is not None: |
| 162 | + raise GMTInvalidInput("Can't provide text if textfiles is specified.") |
160 | 163 | else:
|
161 |
| - if x is not None or y is not None: |
| 164 | + if x is not None or y is not None or textfiles is not None: |
162 | 165 | raise GMTInvalidInput(
|
163 |
| - "Provide either position only, or x/y pairs, not both" |
| 166 | + "Provide either position only, or x/y pairs, or textfiles." |
164 | 167 | )
|
165 |
| - kind = "vectors" |
166 |
| - |
167 |
| - if kind == "vectors" and text is None: |
168 |
| - raise GMTInvalidInput("Must provide text with x/y pairs or position") |
| 168 | + if text is None or is_nonstr_iter(text): |
| 169 | + raise GMTInvalidInput("Text can't be None or array.") |
| 170 | + kind = "file" |
| 171 | + textfiles = "" |
169 | 172 |
|
170 | 173 | # Build the -F option in gmt text.
|
171 | 174 | if "F" not in kwargs.keys() and (
|
@@ -193,19 +196,15 @@ def text_(
|
193 | 196 | extra_arrays.append(kwargs["t"])
|
194 | 197 | kwargs["t"] = ""
|
195 | 198 |
|
| 199 | + # Append text as the last column |
| 200 | + # text must be in str type, see issue #706 |
| 201 | + if kind == "vectors": |
| 202 | + extra_arrays.append(np.atleast_1d(text).astype(str)) |
| 203 | + |
196 | 204 | with Session() as lib:
|
197 |
| - file_context = dummy_context(textfiles) if kind == "file" else "" |
198 |
| - if kind == "vectors": |
199 |
| - if position is not None: |
200 |
| - file_context = dummy_context("") |
201 |
| - else: |
202 |
| - file_context = lib.virtualfile_from_vectors( |
203 |
| - np.atleast_1d(x), |
204 |
| - np.atleast_1d(y), |
205 |
| - *extra_arrays, |
206 |
| - # text must be in str type, see issue #706 |
207 |
| - np.atleast_1d(text).astype(str), |
208 |
| - ) |
| 205 | + file_context = lib.virtualfile_from_data( |
| 206 | + check_kind="vector", data=textfiles, x=x, y=y, extra_arrays=extra_arrays |
| 207 | + ) |
209 | 208 | with file_context as fname:
|
210 | 209 | arg_str = " ".join([fname, build_arg_string(kwargs)])
|
211 | 210 | lib.call_module("text", arg_str)
|
0 commit comments