From 0850b4eede97e504c4b896f73ca2d1e5b88f42d4 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 8 Nov 2024 13:43:05 +0800 Subject: [PATCH 1/2] clib.conversion._to_numpy: Add tests for Python list of strings and NumPy array with string type --- pygmt/tests/test_clib_to_numpy.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index 12b8c1d782d..bba0f9e755e 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -41,11 +41,12 @@ def _check_result(result, expected_dtype): np.complex128, id="complex", ), + pytest.param(["abc", "defh", "12345"], np.str_, id="string"), ], ) -def test_to_numpy_python_types_numeric(data, expected_dtype): +def test_to_numpy_python_types(data, expected_dtype): """ - Test the _to_numpy function with Python built-in numeric types. + Test the _to_numpy function with Python built-in types. """ result = _to_numpy(data) _check_result(result, expected_dtype) @@ -114,6 +115,17 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, expected_dtype): npt.assert_array_equal(result, array, strict=True) +@pytest.mark.parametrize("dtype", [None, np.str_, "U10"]) +def test_to_numpy_ndarray_numpy_dtypes_string(dtype): + """ + Test the _to_numpy function with NumPy arrays of string types. + """ + array = np.array(["abc", "defg", "12345"], dtype=dtype) + result = _to_numpy(array) + _check_result(result, np.str_) + npt.assert_array_equal(result, array) + + ######################################################################################## # Test the _to_numpy function with pandas.Series. # From 79aec3ba22479f1ea9385a873744497b289ce1e9 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 8 Nov 2024 23:56:33 +0800 Subject: [PATCH 2/2] Typo --- pygmt/tests/test_clib_to_numpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_to_numpy.py b/pygmt/tests/test_clib_to_numpy.py index bba0f9e755e..2d39c562f6c 100644 --- a/pygmt/tests/test_clib_to_numpy.py +++ b/pygmt/tests/test_clib_to_numpy.py @@ -41,7 +41,7 @@ def _check_result(result, expected_dtype): np.complex128, id="complex", ), - pytest.param(["abc", "defh", "12345"], np.str_, id="string"), + pytest.param(["abc", "defg", "12345"], np.str_, id="string"), ], ) def test_to_numpy_python_types(data, expected_dtype):