Skip to content

Commit

Permalink
Reduce diff from messy revert handling
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Nov 15, 2024
1 parent a927202 commit 7b00248
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,31 +1001,30 @@ def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray):

def put_strings(self, dataset: ctp.c_void_p, family: str, strings: np.ndarray):
"""
Attach a numpy 1-D array of dtype str as a column on a GMT dataset.
Attach a 1-D numpy array of dtype str as a column on a GMT dataset.
Use this function to attach string type numpy array data to a GMT
dataset and pass it to GMT modules. Wraps ``GMT_Put_Strings``.
Use this function to attach string type numpy array data to a GMT dataset and
pass it to GMT modules. Wraps ``GMT_Put_Strings``.
The dataset must be created by :meth:`pygmt.clib.Session.create_data`
first.
The dataset must be created by :meth:`pygmt.clib.Session.create_data` first.
.. warning::
The numpy array must be C contiguous in memory. If it comes from a
column slice of a 2-D array, for example, you will have to make a
copy. Use :func:`numpy.ascontiguousarray` to make sure your vector
is contiguous (it won't copy if it already is).
The numpy array must be C contiguous in memory. If it comes from a column
slice of a 2-D array, for example, you will have to make a copy. Use
:func:`numpy.ascontiguousarray` to make sure your vector is contiguous (it
won't copy if it already is).
Parameters
----------
dataset : :class:`ctypes.c_void_p`
The ctypes void pointer to a ``GMT_Dataset``. Create it with
:meth:`pygmt.clib.Session.create_data`.
family : str
dataset
The ctypes void pointer to a ``GMT_VECTOR``/``GMT_MATRIX`` data container.
Create it with :meth:`pygmt.clib.Session.create_data`.
family
The family type of the dataset. Can be either ``GMT_IS_VECTOR`` or
``GMT_IS_MATRIX``.
strings : numpy 1-D array
The array that will be attached to the dataset. Must be a 1-D C
contiguous array.
strings
The array that will be attached to the dataset. Must be a 1-D C contiguous
array.
Raises
------
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_clib_put_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_put_strings():
)
x = np.array([1, 2, 3, 4, 5], dtype=np.int32)
y = np.array([6, 7, 8, 9, 10], dtype=np.int32)
strings = np.array(["a", "bc", "defg", "hijklmn", "opqrst"], dtype=str)
strings = np.array(["a", "bc", "defg", "hijklmn", "opqrst"], dtype=np.str_)
lib.put_vector(dataset, column=lib["GMT_X"], vector=x)
lib.put_vector(dataset, column=lib["GMT_Y"], vector=y)
lib.put_strings(
Expand Down

0 comments on commit 7b00248

Please sign in to comment.