Skip to content

Commit f59f93c

Browse files
committed
Add np.ndarray to StringArrayTypes and fix/ignore remaining type errors
1 parent 0a6cda5 commit f59f93c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

pygmt/clib/conversion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
from pygmt.exceptions import GMTInvalidInput
1111

12-
StringArrayTypes = Sequence[str]
12+
StringArrayTypes = Sequence[str] | np.ndarray
1313

1414
try:
1515
import pyarrow as pa
@@ -300,7 +300,7 @@ def strings_to_ctypes_array(strings: StringArrayTypes) -> ctp.Array:
300300
bytes_string_list = [s.encode() for s in strings]
301301
except AttributeError: # 'pyarrow.StringScalar' object has no attribute 'encode'
302302
# Convert pyarrow.StringArray to Python list first
303-
bytes_string_list = [s.encode() for s in strings.to_pylist()]
303+
bytes_string_list = [s.encode() for s in strings.to_pylist()] # type: ignore[union-attr]
304304
return (ctp.c_char_p * len(strings))(*bytes_string_list)
305305

306306

pygmt/clib/session.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
tempfile_from_image,
3535
)
3636

37-
StringArrayTypes = Sequence[str]
37+
StringArrayTypes = Sequence[str] | np.ndarray
3838

3939
try:
4040
import pyarrow as pa
@@ -1005,9 +1005,8 @@ def put_strings(
10051005
self.session_pointer, family_int, dataset, strings_pointer
10061006
)
10071007
if status != 0:
1008-
raise GMTCLibError(
1009-
f"Failed to put strings of type {strings.dtype} into dataset"
1010-
)
1008+
dtype = strings.dtype if hasattr(strings, "dtype") else type(strings)
1009+
raise GMTCLibError(f"Failed to put strings of type {dtype} into dataset")
10111010

10121011
def put_matrix(self, dataset, matrix, pad=0):
10131012
"""

0 commit comments

Comments
 (0)