Skip to content

Commit c07f1b6

Browse files
authored
clib.conversion._to_numpy: Add tests for pyarrow.array with pyarrow string/large_string/string_view types (#3608)
1 parent 4d2f8cb commit c07f1b6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

+23
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def test_to_numpy_pandas_series_pyarrow_dtypes_date(dtype, expected_dtype):
205205
# - int8, int16, int32, int64
206206
# - uint8, uint16, uint32, uint64
207207
# - float16, float32, float64
208+
# - String types: string/utf8, large_string/large_utf8, string_view
208209
# - Date types:
209210
# - date32[day]
210211
# - date64[ms]
@@ -278,6 +279,28 @@ def test_to_numpy_pyarrow_array_pyarrow_dtypes_numeric_with_na(dtype, expected_d
278279
npt.assert_array_equal(result, array)
279280

280281

282+
@pytest.mark.skipif(not _HAS_PYARROW, reason="pyarrow is not installed")
283+
@pytest.mark.parametrize(
284+
"dtype",
285+
[
286+
None,
287+
"string",
288+
"utf8", # alias for string
289+
"large_string",
290+
"large_utf8", # alias for large_string
291+
"string_view",
292+
],
293+
)
294+
def test_to_numpy_pyarrow_array_pyarrow_dtypes_string(dtype):
295+
"""
296+
Test the _to_numpy function with PyArrow arrays of PyArrow string types.
297+
"""
298+
array = pa.array(["abc", "defg", "12345"], type=dtype)
299+
result = _to_numpy(array)
300+
_check_result(result, np.str_)
301+
npt.assert_array_equal(result, array)
302+
303+
281304
@pytest.mark.skipif(not _HAS_PYARROW, reason="pyarrow is not installed")
282305
@pytest.mark.parametrize(
283306
("dtype", "expected_dtype"),

0 commit comments

Comments
 (0)