Skip to content

Commit 9a10d9e

Browse files
committed
clib.conversion._to_numpy: Add tests for Python list of strings and NumPy array with string type (#3601)
1 parent ee26ac7 commit 9a10d9e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pygmt/tests/test_clib_to_numpy.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ def _check_result(result, expected_dtype):
4848
np.complex128,
4949
id="complex",
5050
),
51+
pytest.param(["abc", "defg", "12345"], np.str_, id="string"),
5152
],
5253
)
53-
def test_to_numpy_python_types_numeric(data, expected_dtype):
54+
def test_to_numpy_python_types(data, expected_dtype):
5455
"""
55-
Test the _to_numpy function with Python built-in numeric types.
56+
Test the _to_numpy function with Python built-in types.
5657
"""
5758
result = _to_numpy(data)
5859
_check_result(result, expected_dtype)
@@ -121,6 +122,17 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, expected_dtype):
121122
npt.assert_array_equal(result, array, strict=True)
122123

123124

125+
@pytest.mark.parametrize("dtype", [None, np.str_, "U10"])
126+
def test_to_numpy_ndarray_numpy_dtypes_string(dtype):
127+
"""
128+
Test the _to_numpy function with NumPy arrays of string types.
129+
"""
130+
array = np.array(["abc", "defg", "12345"], dtype=dtype)
131+
result = _to_numpy(array)
132+
_check_result(result, np.str_)
133+
npt.assert_array_equal(result, array)
134+
135+
124136
########################################################################################
125137
# Test the _to_numpy function with pandas.Series.
126138
#

0 commit comments

Comments
 (0)