Skip to content

Commit d3f1611

Browse files
committed
clib.conversion._to_numpy: Add tests for pandas.Series with pandas string dtypes
1 parent 189f376 commit d3f1611

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
from packaging.version import Version
1212
from pygmt.clib.conversion import _to_numpy
13+
from pygmt.helpers.testing import skip_if_no
1314

1415
try:
1516
import pyarrow as pa
@@ -161,6 +162,31 @@ def test_to_numpy_pandas_series_numpy_dtypes_numeric(dtype, expected_dtype):
161162
npt.assert_array_equal(result, series)
162163

163164

165+
@pytest.mark.parametrize(
166+
"dtype",
167+
[
168+
None,
169+
np.str_,
170+
"U10",
171+
"string[python]",
172+
pytest.param("string[pyarrow]", marks=skip_if_no(package="pyarrow")),
173+
pytest.param("string[pyarrow_numpy]", marks=skip_if_no(package="pyarrow")),
174+
],
175+
)
176+
def test_to_numpy_pandas_series_pandas_dtypes_string(dtype):
177+
"""
178+
Test the _to_numpy function with pandas.Series of pandas string types.
179+
180+
In pandas, string arrays can be specified in multiple ways.
181+
182+
Reference: https://pandas.pydata.org/docs/reference/api/pandas.StringDtype.html
183+
"""
184+
array = pd.Series(["abc", "defg", "12345"], dtype=dtype)
185+
result = _to_numpy(array)
186+
_check_result(result, np.str_)
187+
npt.assert_array_equal(result, array)
188+
189+
164190
########################################################################################
165191
# Test the _to_numpy function with PyArrow arrays.
166192
#

0 commit comments

Comments
 (0)