Skip to content

Commit 0cdb7fc

Browse files
committed
pyarrow: Support pyarrow arrays with string/large_string/string_view types
1 parent 66b22dc commit 0cdb7fc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pygmt/clib/conversion.py

Lines changed: 8 additions & 3 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.
160-
dtypes: dict[str, str | type] = {
159+
# Mapping of unsupported dtypes to expected NumPy dtypes.
160+
dtypes: dict[str, type | str] = {
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]": "datetime64[D]",
162167
"date64[ms][pyarrow]": "datetime64[ms]",
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)