Skip to content

Commit 243b488

Browse files
authored
clib.conversion.strings_to_ctypes_array: Add a doctest for numpy string array (#3652)
1 parent 988746b commit 243b488

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pygmt/clib/conversion.py

+7
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ def strings_to_ctypes_array(strings: Sequence[str] | np.ndarray) -> ctp.Array:
307307
<class 'pygmt.clib.conversion.c_char_p_Array_3'>
308308
>>> [s.decode() for s in ctypes_array]
309309
['first', 'second', 'third']
310+
311+
>>> strings = np.array(["first", "second", "third"])
312+
>>> ctypes_array = strings_to_ctypes_array(strings)
313+
>>> type(ctypes_array)
314+
<class 'pygmt.clib.conversion.c_char_p_Array_3'>
315+
>>> [s.decode() for s in ctypes_array]
316+
['first', 'second', 'third']
310317
"""
311318
return (ctp.c_char_p * len(strings))(*[s.encode() for s in strings])
312319

0 commit comments

Comments
 (0)