Skip to content

Commit 4c4e064

Browse files
committed
Check passing pyarrow.array with string type to virtualfile_from_vectors
1 parent 1f32a7c commit 4c4e064

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

pygmt/tests/test_clib_virtualfiles.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
from pygmt import clib
1313
from pygmt.exceptions import GMTCLibError, GMTInvalidInput
1414
from pygmt.helpers import GMTTempFile
15+
from pygmt.helpers.testing import skip_if_no
1516
from pygmt.tests.test_clib import mock
1617

18+
try:
19+
import pyarrow as pa
20+
except ImportError:
21+
pa = None
22+
1723
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
1824
POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt")
1925

@@ -210,16 +216,28 @@ def test_virtualfile_from_vectors(dtypes):
210216
assert output == expected
211217

212218

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):
215233
"""
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.
218236
"""
219237
size = 5
220238
x = np.arange(size, dtype=np.int32)
221239
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)
223241
with clib.Session() as lib:
224242
with lib.virtualfile_from_vectors(x, y, strings) as vfile:
225243
with GMTTempFile() as outfile:

0 commit comments

Comments
 (0)