Skip to content

Commit 8b9ec5a

Browse files
authored
Fix the bug of converting Python sequence of datetime-like objects (#3760)
Convert unrecognized objects to datetime before converting to string dtype
1 parent 77a2d59 commit 8b9ec5a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pygmt/clib/conversion.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ def _to_numpy(data: Any) -> np.ndarray:
205205

206206
array = np.ascontiguousarray(data, dtype=numpy_dtype)
207207

208+
# Check if a np.object_ or np.str_ array can be converted to np.datetime64.
209+
if array.dtype.type in {np.object_, np.str_}:
210+
with contextlib.suppress(TypeError, ValueError):
211+
return np.ascontiguousarray(array, dtype=np.datetime64)
212+
208213
# Check if a np.object_ array can be converted to np.str_.
209214
if array.dtype == np.object_:
210215
with contextlib.suppress(TypeError, ValueError):

0 commit comments

Comments
 (0)