Skip to content

Commit 9f1c318

Browse files
committed
clib.conversion._to_numpy: Add tests for pyarrow.array with pyarrow string types
1 parent ff9daae commit 9f1c318

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def test_to_numpy_pandas_series_numpy_dtypes_numeric(dtype, expected_dtype):
170170
# - int8, int16, int32, int64
171171
# - uint8, uint16, uint32, uint64
172172
# - float16, float32, float64
173+
# - String dtypes: string/utf8, large_string/large_utf8, string_view
173174
#
174175
# In PyArrow, array types can be specified in two ways:
175176
#
@@ -238,3 +239,25 @@ def test_to_numpy_pyarrow_array_pyarrow_dtypes_numeric_with_na(dtype, expected_d
238239
result = _to_numpy(array)
239240
_check_result(result, expected_dtype)
240241
npt.assert_array_equal(result, array)
242+
243+
244+
@pytest.mark.skipif(not _HAS_PYARROW, reason="pyarrow is not installed")
245+
@pytest.mark.parametrize(
246+
"dtype",
247+
[
248+
None,
249+
"string",
250+
"utf8", # alias for string
251+
"large_string",
252+
"large_utf8", # alias for large_string
253+
"string_view",
254+
],
255+
)
256+
def test_to_numpy_pyarrow_array_pyarrow_dtypes_string(dtype):
257+
"""
258+
Test the _to_numpy function with PyArrow arrays of PyArrow string types.
259+
"""
260+
array = pa.array(["abc", "defg", "12345"], type=dtype)
261+
result = _to_numpy(array)
262+
_check_result(result, np.str_)
263+
npt.assert_array_equal(result, array)

0 commit comments

Comments
 (0)