Skip to content

Commit 0bba51e

Browse files
committed
Fix the bug of converting Python sequence of datetime-like objects (#3760)
Convert unrecognized objects to datetime before converting to string dtype
1 parent dd66477 commit 0bba51e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pygmt/clib/conversion.py

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ def _to_numpy(data: Any) -> np.ndarray:
194194

195195
array = np.ascontiguousarray(data, dtype=numpy_dtype)
196196

197+
# Check if a np.object_ or np.str_ array can be converted to np.datetime64.
198+
if array.dtype.type in {np.object_, np.str_}:
199+
with contextlib.suppress(TypeError, ValueError):
200+
return np.ascontiguousarray(array, dtype=np.datetime64)
201+
197202
# Check if a np.object_ array can be converted to np.str_.
198203
if array.dtype == np.object_:
199204
with contextlib.suppress(TypeError, ValueError):

0 commit comments

Comments
 (0)