|
9 | 9 | import pandas as pd
|
10 | 10 | import pytest
|
11 | 11 | import xarray as xr
|
| 12 | +from packaging.version import Version |
12 | 13 | from pygmt import clib
|
| 14 | +from pygmt.clib import __gmt_version__ |
13 | 15 | from pygmt.exceptions import GMTInvalidInput
|
14 |
| -from pygmt.helpers import GMTTempFile |
| 16 | +from pygmt.helpers import GMTTempFile, data_kind |
15 | 17 |
|
16 | 18 | POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
|
17 | 19 |
|
@@ -101,3 +103,27 @@ def test_virtualfile_in_fail_non_valid_data(data):
|
101 | 103 | z=data[:, 2],
|
102 | 104 | data=data,
|
103 | 105 | )
|
| 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