Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clib.conversion._to_numpy: Add tests for Python list of strings and NumPy array with string type #3601

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pygmt/tests/test_clib_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def _check_result(result, expected_dtype):
np.complex128,
id="complex",
),
pytest.param(["abc", "defg", "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)
Expand Down Expand Up @@ -121,6 +122,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.
#
Expand Down
Loading