diff --git a/pygmt/clib/conversion.py b/pygmt/clib/conversion.py index 59fa0d584cd..4716fe09b5e 100644 --- a/pygmt/clib/conversion.py +++ b/pygmt/clib/conversion.py @@ -156,8 +156,13 @@ def _to_numpy(data: Any) -> np.ndarray: array The C contiguous NumPy array. """ - # Mapping of unsupported dtypes to the expected NumPy dtype. - dtypes: dict[str, str | type] = { + # Mapping of unsupported dtypes to expected NumPy dtypes. + dtypes: dict[str, type | str] = { + # For string dtypes. + "large_string": np.str_, # pa.large_string and pa.large_utf8 + "string": np.str_, # pa.string and pa.utf8 + "string_view": np.str_, # pa.string_view + # For datetime dtypes. "date32[day][pyarrow]": "datetime64[D]", "date64[ms][pyarrow]": "datetime64[ms]", } @@ -173,7 +178,7 @@ def _to_numpy(data: Any) -> np.ndarray: # we can remove the workaround in PyGMT v0.17.0. array = np.ascontiguousarray(data.astype(float)) else: - vec_dtype = str(getattr(data, "dtype", "")) + vec_dtype = str(getattr(data, "dtype", getattr(data, "type", ""))) array = np.ascontiguousarray(data, dtype=dtypes.get(vec_dtype)) return array