Skip to content

Commit 3d401bb

Browse files
authored
clib: Fix the bug when passing multiple columns of strings with variable lengths to the GMT C API (#2719)
1 parent 5ecef3b commit 3d401bb

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

pygmt/clib/session.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,7 @@ def virtualfile_from_vectors(self, *vectors):
12911291
if len(string_arrays) == 1:
12921292
strings = string_arrays[0]
12931293
elif len(string_arrays) > 1:
1294-
strings = np.apply_along_axis(
1295-
func1d=" ".join, axis=0, arr=string_arrays
1296-
)
1294+
strings = np.array([" ".join(vals) for vals in zip(*string_arrays)])
12971295
strings = np.asanyarray(a=strings, dtype=str)
12981296
self.put_strings(
12991297
dataset, family="GMT_IS_VECTOR|GMT_IS_DUPLICATE", strings=strings

pygmt/tests/test_clib.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ def test_virtualfile_from_vectors_two_string_or_object_columns(dtype):
556556
size = 5
557557
x = np.arange(size, dtype=np.int32)
558558
y = np.arange(size, size * 2, 1, dtype=np.int32)
559-
strings1 = np.array(["a", "bc", "def", "ghij", "klmno"], dtype=dtype)
559+
# Catch bug in https://github.com/GenericMappingTools/pygmt/pull/2719
560+
strings1 = np.array(["a", "bc", "def", "ghij", "klmnolooong"], dtype=dtype)
560561
strings2 = np.array(["pqrst", "uvwx", "yz!", "@#", "$"], dtype=dtype)
561562
with clib.Session() as lib:
562563
with lib.virtualfile_from_vectors(x, y, strings1, strings2) as vfile:

0 commit comments

Comments
 (0)