|
12 | 12 | from pygmt import clib
|
13 | 13 | from pygmt.exceptions import GMTCLibError, GMTInvalidInput
|
14 | 14 | from pygmt.helpers import GMTTempFile
|
| 15 | +from pygmt.helpers.testing import skip_if_no |
15 | 16 | from pygmt.tests.test_clib import mock
|
16 | 17 |
|
| 18 | +try: |
| 19 | + import pyarrow as pa |
| 20 | +except ImportError: |
| 21 | + pa = None |
| 22 | + |
17 | 23 | TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
|
18 | 24 | POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt")
|
19 | 25 |
|
@@ -210,16 +216,28 @@ def test_virtualfile_from_vectors(dtypes):
|
210 | 216 | assert output == expected
|
211 | 217 |
|
212 | 218 |
|
213 |
| -@pytest.mark.parametrize("dtype", [str, object]) |
214 |
| -def test_virtualfile_from_vectors_one_string_or_object_column(dtype): |
| 219 | +@pytest.mark.parametrize( |
| 220 | + ("array_func", "dtype"), |
| 221 | + [ |
| 222 | + pytest.param(np.array, {"dtype": str}, id="str"), |
| 223 | + pytest.param(np.array, {"dtype": object}, id="object"), |
| 224 | + pytest.param( |
| 225 | + getattr(pa, "array", None), |
| 226 | + {}, # pa.string() |
| 227 | + marks=skip_if_no(package="pyarrow"), |
| 228 | + id="pyarrow", |
| 229 | + ), |
| 230 | + ], |
| 231 | +) |
| 232 | +def test_virtualfile_from_vectors_one_string_or_object_column(array_func, dtype): |
215 | 233 | """
|
216 |
| - Test passing in one column with string or object dtype into virtual file |
217 |
| - dataset. |
| 234 | + Test passing in one column with string (numpy/pyarrow) or object (numpy) |
| 235 | + dtype into virtual file dataset. |
218 | 236 | """
|
219 | 237 | size = 5
|
220 | 238 | x = np.arange(size, dtype=np.int32)
|
221 | 239 | y = np.arange(size, size * 2, 1, dtype=np.int32)
|
222 |
| - strings = np.array(["a", "bc", "defg", "hijklmn", "opqrst"], dtype=dtype) |
| 240 | + strings = array_func(["a", "bc", "defg", "hijklmn", "opqrst"], **dtype) |
223 | 241 | with clib.Session() as lib:
|
224 | 242 | with lib.virtualfile_from_vectors(x, y, strings) as vfile:
|
225 | 243 | with GMTTempFile() as outfile:
|
|
0 commit comments