|
11 | 11 | from pygmt.clib.session import DTYPES_NUMERIC
|
12 | 12 | from pygmt.exceptions import GMTInvalidInput
|
13 | 13 | from pygmt.helpers import GMTTempFile
|
| 14 | +from pygmt.helpers.testing import skip_if_no |
| 15 | + |
| 16 | +try: |
| 17 | + import pyarrow as pa |
| 18 | + |
| 19 | + pa_array = pa.array |
| 20 | +except ImportError: |
| 21 | + pa_array = None |
14 | 22 |
|
15 | 23 |
|
16 | 24 | @pytest.fixture(scope="module", name="dtypes")
|
@@ -53,17 +61,30 @@ def test_virtualfile_from_vectors(dtypes):
|
53 | 61 |
|
54 | 62 |
|
55 | 63 | @pytest.mark.benchmark
|
56 |
| -@pytest.mark.parametrize("dtype", [str, object]) |
57 |
| -def test_virtualfile_from_vectors_one_string_or_object_column(dtype): |
58 |
| - """ |
59 |
| - Test passing in one column with string or object dtype into virtual file dataset. |
| 64 | +@pytest.mark.parametrize( |
| 65 | + ("array_func", "dtype"), |
| 66 | + [ |
| 67 | + pytest.param(np.array, {"dtype": np.str_}, id="str"), |
| 68 | + pytest.param(np.array, {"dtype": np.object_}, id="object"), |
| 69 | + pytest.param( |
| 70 | + pa_array, |
| 71 | + {}, # {"type": pa.string()} |
| 72 | + marks=skip_if_no(package="pyarrow"), |
| 73 | + id="pyarrow", |
| 74 | + ), |
| 75 | + ], |
| 76 | +) |
| 77 | +def test_virtualfile_from_vectors_one_string_or_object_column(array_func, dtype): |
| 78 | + """ |
| 79 | + Test passing in one column with string (numpy/pyarrow) or object (numpy) |
| 80 | + dtype into virtual file dataset. |
60 | 81 | """
|
61 | 82 | size = 5
|
62 | 83 | x = np.arange(size, dtype=np.int32)
|
63 | 84 | y = np.arange(size, size * 2, 1, dtype=np.int32)
|
64 |
| - strings = np.array(["a", "bc", "defg", "hijklmn", "opqrst"], dtype=dtype) |
| 85 | + strings = array_func(["a", "bc", "defg", "hijklmn", "opqrst"], **dtype) |
65 | 86 | with clib.Session() as lib:
|
66 |
| - with lib.virtualfile_from_vectors((x, y, strings)) as vfile: |
| 87 | + with lib.virtualfile_from_vectors(vectors=(x, y, strings)) as vfile: |
67 | 88 | with GMTTempFile() as outfile:
|
68 | 89 | lib.call_module("convert", [vfile, f"->{outfile.name}"])
|
69 | 90 | output = outfile.read(keep_tabs=True)
|
|
0 commit comments