Skip to content

Commit f10175f

Browse files
committed
Explicitly mapping string/large_string/string_view to np.str_
1 parent 9f1c318 commit f10175f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pygmt/clib/conversion.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,13 @@ def _to_numpy(data: Any) -> np.ndarray:
156156
array
157157
The C contiguous NumPy array.
158158
"""
159-
# Mapping of unsupported dtypes to the expected NumPy dtype.
159+
# Mapping of unsupported dtypes to expected NumPy dtypes.
160160
dtypes: dict[str, type] = {
161+
# For string dtypes.
162+
"large_string": np.str_, # pa.large_string and pa.large_utf8
163+
"string": np.str_, # pa.string and pa.utf8
164+
"string_view": np.str_, # pa.string_view
165+
# For datetime dtypes.
161166
"date32[day][pyarrow]": np.datetime64,
162167
"date64[ms][pyarrow]": np.datetime64,
163168
}
@@ -173,7 +178,7 @@ def _to_numpy(data: Any) -> np.ndarray:
173178
# we can remove the workaround in PyGMT v0.17.0.
174179
array = np.ascontiguousarray(data.astype(float))
175180
else:
176-
vec_dtype = str(getattr(data, "dtype", ""))
181+
vec_dtype = str(getattr(data, "dtype", getattr(data, "type", "")))
177182
array = np.ascontiguousarray(data, dtype=dtypes.get(vec_dtype))
178183
return array
179184

0 commit comments

Comments
 (0)