Skip to content

Commit 6390e04

Browse files
committed
Try passing "GMT_IS_VECTOR" family type to put_strings
1 parent 88eef3a commit 6390e04

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

pygmt/clib/session.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
np.uint64: "GMT_ULONG",
5757
np.uint32: "GMT_UINT",
5858
np.datetime64: "GMT_DATETIME",
59-
np.str_: "GMT_TEXT",
6059
}
6160

6261

@@ -792,15 +791,15 @@ def put_vector(self, dataset, column, vector):
792791
)
793792
)
794793

795-
def put_strings(self, dataset, strings):
794+
def put_strings(self, dataset, family, strings):
796795
"""
797796
Attach a numpy 1D array of dtype str as a column on a GMT dataset.
798797
799798
Use this function to attach string type numpy array data to a GMT
800799
dataset and pass it to GMT modules. Wraps ``GMT_Put_Strings``.
801800
802801
The dataset must be created by :meth:`~gmt.clib.Session.create_data`
803-
first. Use ``family='GMT_IS_DATASET|GMT_VIA_VECTOR'``.
802+
first.
804803
805804
.. warning::
806805
The numpy array must be C contiguous in memory. If it comes from a
@@ -813,6 +812,9 @@ def put_strings(self, dataset, strings):
813812
dataset : :class:`ctypes.c_void_p`
814813
The ctypes void pointer to a ``GMT_Dataset``. Create it with
815814
:meth:`~gmt.clib.Session.create_data`.
815+
family : str
816+
The family type of the dataset. Can be either ``GMT_IS_VECTOR`` or
817+
``GMT_IS_MATRIX``.
816818
strings : numpy 1d-array
817819
The array that will be attached to the dataset. Must be a 1d C
818820
contiguous array.
@@ -830,9 +832,10 @@ def put_strings(self, dataset, strings):
830832
restype=ctp.c_int,
831833
)
832834

833-
gmt_type = self._check_dtype_and_dim(strings, ndim=1)
834-
strings_pointer = strings.ctypes.data_as(ctp.c_void_p)
835-
status = c_put_strings(self.session_pointer, dataset, gmt_type, strings_pointer)
835+
strings_pointer = strings.ctypes.data_as(ctp.c_char_p)
836+
status = c_put_strings(
837+
self.session_pointer, self[family], dataset, strings_pointer
838+
)
836839
if status != 0:
837840
raise GMTCLibError(
838841
f"Failed to put strings of type {strings.dtype} into dataset"

pygmt/tests/test_clib_put.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_put_strings():
2121
dim=[1, 5, 1, 0], # columns, rows, layers, dtype
2222
)
2323
s = np.array(["a", "b", "c", "d", "e"], dtype=np.str)
24-
lib.put_strings(dataset, strings=s)
24+
lib.put_strings(dataset, family="GMT_IS_VECTOR", strings=s)
2525
# Turns out wesn doesn't matter for Datasets
2626
wesn = [0] * 6
2727
# Save the data to a file to see if it's being accessed correctly

0 commit comments

Comments
 (0)