Skip to content

Commit

Permalink
Fix the bug of converting Python sequence of datetime-like objects (#…
Browse files Browse the repository at this point in the history
…3760)

Convert unrecognized objects to datetime before converting to string dtype
  • Loading branch information
seisman committed Jan 17, 2025
1 parent dd66477 commit 0bba51e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def _to_numpy(data: Any) -> np.ndarray:

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

# Check if a np.object_ or np.str_ array can be converted to np.datetime64.
if array.dtype.type in {np.object_, np.str_}:
with contextlib.suppress(TypeError, ValueError):
return np.ascontiguousarray(array, dtype=np.datetime64)

# Check if a np.object_ array can be converted to np.str_.
if array.dtype == np.object_:
with contextlib.suppress(TypeError, ValueError):
Expand Down

0 comments on commit 0bba51e

Please sign in to comment.