Skip to content

Commit 1f32a7c

Browse files
committed
Check passing pyarrow.array with string type to pygmt.text
Ensure that pyarrow.array objects with string type can be read by pygmt.text.
1 parent 75e56e5 commit 1f32a7c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pygmt/tests/test_text.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from pygmt import Figure
99
from pygmt.exceptions import GMTCLibError, GMTInvalidInput
1010
from pygmt.helpers import GMTTempFile
11+
from pygmt.helpers.testing import skip_if_no
12+
13+
try:
14+
import pyarrow as pa
15+
except ImportError:
16+
pa = None
1117

1218
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
1319
POINTS_DATA = os.path.join(TEST_DATA_DIR, "points.txt")
@@ -47,8 +53,20 @@ def test_text_single_line_of_text(region, projection):
4753

4854

4955
@pytest.mark.benchmark
50-
@pytest.mark.mpl_image_compare
51-
def test_text_multiple_lines_of_text(region, projection):
56+
@pytest.mark.mpl_image_compare(filename="test_text_multiple_lines_of_text.png")
57+
@pytest.mark.parametrize(
58+
"array_func",
59+
[
60+
list,
61+
pytest.param(np.array, id="numpy"),
62+
pytest.param(
63+
getattr(pa, "array", None),
64+
marks=skip_if_no(package="pyarrow"),
65+
id="pyarrow",
66+
),
67+
],
68+
)
69+
def test_text_multiple_lines_of_text(region, projection, array_func):
5270
"""
5371
Place multiple lines of text at their respective x, y locations.
5472
"""
@@ -58,7 +76,7 @@ def test_text_multiple_lines_of_text(region, projection):
5876
projection=projection,
5977
x=[1.2, 1.6],
6078
y=[0.6, 0.3],
61-
text=["This is a line of text", "This is another line of text"],
79+
text=array_func(["This is a line of text", "This is another line of text"]),
6280
)
6381
return fig
6482

0 commit comments

Comments
 (0)