Skip to content

Commit cfa32ed

Browse files
committed
Add a test for passing string dtype matrix
1 parent 2b054b6 commit cfa32ed

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pygmt/tests/test_clib_virtualfile_in.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import pandas as pd
1010
import pytest
1111
import xarray as xr
12+
from packaging.version import Version
1213
from pygmt import clib
14+
from pygmt.clib import __gmt_version__
1315
from pygmt.exceptions import GMTInvalidInput
14-
from pygmt.helpers import GMTTempFile
16+
from pygmt.helpers import GMTTempFile, data_kind
1517

1618
POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
1719

@@ -101,3 +103,27 @@ def test_virtualfile_in_fail_non_valid_data(data):
101103
z=data[:, 2],
102104
data=data,
103105
)
106+
107+
108+
@pytest.mark.xfail(
109+
condition=Version(__gmt_version__) <= Version("6.5.0"),
110+
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/8600",
111+
)
112+
def test_virtualfile_in_matrix_string_dtype():
113+
"""
114+
Pass a string dtype matrix should work and the matrix should be passed via a series
115+
of vectors.
116+
"""
117+
data = np.array([["11:30W", "30:30S"], ["12:30W", "30:00S"]])
118+
assert data_kind(data) == "matrix" # data is recognized as "matrix" kind
119+
assert data.dtype.type == np.str_
120+
assert data.dtype.kind not in "iuf" # dtype is not in numeric dtypes
121+
122+
with clib.Session() as lib:
123+
with lib.virtualfile_in(data=data) as vintbl:
124+
with GMTTempFile() as outfile:
125+
lib.call_module("info", [vintbl, "-C", f"->{outfile.name}"])
126+
output = outfile.read(keep_tabs=False)
127+
assert output == "347.5 348.5 -30.5 -30\n"
128+
# Should check that lib.virtualfile_from_vectors is called once,
129+
# not lib.virtualfile_from_matrix, but it's technically complicated.

0 commit comments

Comments
 (0)