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
  • Loading branch information
seisman committed Nov 14, 2024
1 parent 66b22dc commit a7cf93f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,15 @@ 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] = {
"date32[day][pyarrow]": "datetime64[D]",
"date64[ms][pyarrow]": "datetime64[ms]",
# 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]": np.datetime64,
"date64[ms][pyarrow]": np.datetime64,
}

if (
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 a7cf93f

Please sign in to comment.