Skip to content

Commit

Permalink
Try to fix type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Oct 11, 2024
1 parent cfda386 commit 0a6cda5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
import numpy as np
from pygmt.exceptions import GMTInvalidInput

StringArrayTypes = Sequence[str]

try:
import pyarrow as pa

StringArrayTypes |= pa.StringArray
except ImportError:
pa = None


def dataarray_to_matrix(grid):
"""
Transform an xarray.DataArray into a data 2-D array and metadata.
Expand Down Expand Up @@ -267,7 +272,7 @@ def sequence_to_ctypes_array(
return (ctype * size)(*sequence)


def strings_to_ctypes_array(strings: Sequence[str] | pa.StringArray) -> ctp.Array:
def strings_to_ctypes_array(strings: StringArrayTypes) -> ctp.Array:
"""
Convert a sequence (e.g., a list) of strings or a pyarrow.StringArray into a ctypes
array.
Expand Down
7 changes: 6 additions & 1 deletion pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@
tempfile_from_image,
)

StringArrayTypes = Sequence[str]

try:
import pyarrow as pa

StringArrayTypes |= pa.StringArray
except ImportError:
pa = None


FAMILIES = [
"GMT_IS_DATASET", # Entity is a data table
"GMT_IS_GRID", # Entity is a grid
Expand Down Expand Up @@ -945,7 +950,7 @@ def put_strings(
self,
dataset: ctp.c_void_p,
family: Literal["GMT_IS_VECTOR", "GMT_IS_MATRIX"],
strings: Sequence[str] | pa.StringArray,
strings: StringArrayTypes,
):
"""
Attach a 1-D numpy array of dtype str or pyarrow.StringArray as a column on a
Expand Down

0 comments on commit 0a6cda5

Please sign in to comment.