Skip to content

Commit

Permalink
pyarrow: Support pyarrow arrays with string/large_string/string_view …
Browse files Browse the repository at this point in the history
…types (#3619)
  • Loading branch information
seisman authored Nov 15, 2024
1 parent 66b22dc commit 4d2f8cb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
}
Expand All @@ -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

Expand Down

0 comments on commit 4d2f8cb

Please sign in to comment.