Skip to content

Commit 0a6cda5

Browse files
committed
Try to fix type hints
1 parent cfda386 commit 0a6cda5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pygmt/clib/conversion.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
import numpy as np
1010
from pygmt.exceptions import GMTInvalidInput
1111

12+
StringArrayTypes = Sequence[str]
13+
1214
try:
1315
import pyarrow as pa
16+
17+
StringArrayTypes |= pa.StringArray
1418
except ImportError:
1519
pa = None
1620

21+
1722
def dataarray_to_matrix(grid):
1823
"""
1924
Transform an xarray.DataArray into a data 2-D array and metadata.
@@ -267,7 +272,7 @@ def sequence_to_ctypes_array(
267272
return (ctype * size)(*sequence)
268273

269274

270-
def strings_to_ctypes_array(strings: Sequence[str] | pa.StringArray) -> ctp.Array:
275+
def strings_to_ctypes_array(strings: StringArrayTypes) -> ctp.Array:
271276
"""
272277
Convert a sequence (e.g., a list) of strings or a pyarrow.StringArray into a ctypes
273278
array.

pygmt/clib/session.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@
3434
tempfile_from_image,
3535
)
3636

37+
StringArrayTypes = Sequence[str]
38+
3739
try:
3840
import pyarrow as pa
41+
42+
StringArrayTypes |= pa.StringArray
3943
except ImportError:
4044
pa = None
4145

46+
4247
FAMILIES = [
4348
"GMT_IS_DATASET", # Entity is a data table
4449
"GMT_IS_GRID", # Entity is a grid
@@ -945,7 +950,7 @@ def put_strings(
945950
self,
946951
dataset: ctp.c_void_p,
947952
family: Literal["GMT_IS_VECTOR", "GMT_IS_MATRIX"],
948-
strings: Sequence[str] | pa.StringArray,
953+
strings: StringArrayTypes,
949954
):
950955
"""
951956
Attach a 1-D numpy array of dtype str or pyarrow.StringArray as a column on a

0 commit comments

Comments
 (0)