Skip to content

Commit dac7e8e

Browse files
committed
Try to convert np.object_ into string type
1 parent 01ba317 commit dac7e8e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pygmt/clib/conversion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Functions to convert data types into ctypes friendly formats.
33
"""
44

5+
import contextlib
56
import ctypes as ctp
67
import warnings
78
from collections.abc import Sequence
@@ -178,6 +179,11 @@ def _to_numpy(data: Any) -> np.ndarray:
178179
else:
179180
vec_dtype = str(getattr(data, "dtype", ""))
180181
array = np.ascontiguousarray(data, dtype=dtypes.get(vec_dtype))
182+
183+
# Check if a np.object_ array can be converted to np.str_.
184+
if array.dtype == np.object_:
185+
with contextlib.suppress(TypeError, ValueError):
186+
return np.ascontiguousarray(array, dtype=np.str_)
181187
return array
182188

183189

0 commit comments

Comments
 (0)