|
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,21 @@ 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: |
| 165 | + raise GMTInvalidInput( |
| 166 | + "Provide either position only, or x/y pairs, or textfiles." |
| 167 | + ) |
| 168 | + if text is None or is_nonstr_iter(text): |
162 | 169 | raise GMTInvalidInput(
|
163 | 170 | "Provide either position only, or x/y pairs, not both"
|
164 | 171 | )
|
165 |
| - kind = "vectors" |
166 |
| - |
167 |
| - if kind == "vectors" and text is None: |
168 |
| - raise GMTInvalidInput("Must provide text with x/y pairs or position") |
| 172 | + kind = "file" |
| 173 | + textfiles = "" |
169 | 174 |
|
170 | 175 | # Build the -F option in gmt text.
|
171 | 176 | if "F" not in kwargs.keys() and (
|
@@ -193,19 +198,15 @@ def text_(
|
193 | 198 | extra_arrays.append(kwargs["t"])
|
194 | 199 | kwargs["t"] = ""
|
195 | 200 |
|
| 201 | + # Append text as the last column |
| 202 | + # text must be in str type, see issue #706 |
| 203 | + if kind == "vectors": |
| 204 | + extra_arrays.append(np.atleast_1d(text).astype(str)) |
| 205 | + |
196 | 206 | 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 |
| - ) |
| 207 | + file_context = lib.virtualfile_from_data( |
| 208 | + check_kind="vector", data=textfiles, x=x, y=y, extra_arrays=extra_arrays |
| 209 | + ) |
209 | 210 | with file_context as fname:
|
210 | 211 | arg_str = " ".join([fname, build_arg_string(kwargs)])
|
211 | 212 | lib.call_module("text", arg_str)
|
0 commit comments