Skip to content

Commit 1e1ca8e

Browse files
committed
Add tests for pandas.Series with NumPy numeric dtypes
1 parent 7aa67f4 commit 1e1ca8e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

+45
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
import numpy.testing as npt
7+
import pandas as pd
78
import pytest
89
from pygmt.clib.conversion import _to_numpy
910
from pygmt.clib.session import DTYPES
@@ -80,3 +81,47 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, supported):
8081
result = _to_numpy(array)
8182
_check_result(result, supported)
8283
npt.assert_array_equal(result, array)
84+
85+
86+
########################################################################################
87+
# Test the _to_numpy function with pandas.Series.
88+
#
89+
# In pandas, dtype can be specified by
90+
#
91+
# 1. NumPy dtypes (see above)
92+
# 2. pandas nullable dtypes
93+
# 3. PyArrow dtypes
94+
#
95+
# Reference: https://pandas.pydata.org/docs/reference/arrays.html
96+
########################################################################################
97+
@pytest.mark.parametrize(
98+
("dtype", "supported"),
99+
[
100+
(np.int8, True),
101+
(np.int16, True),
102+
(np.int32, True),
103+
(np.int64, True),
104+
(np.longlong, True),
105+
(np.uint8, True),
106+
(np.uint16, True),
107+
(np.uint32, True),
108+
(np.uint64, True),
109+
(np.ulonglong, True),
110+
(np.float16, False),
111+
(np.float32, True),
112+
(np.float64, True),
113+
(np.longdouble, False),
114+
(np.complex64, False),
115+
(np.complex128, False),
116+
(np.clongdouble, False),
117+
],
118+
)
119+
def test_to_numpy_pandas_series_numpy_dtypes_numeric(dtype, supported):
120+
"""
121+
Test the _to_numpy function with pandas.Series of NumPy numeric dtypes.
122+
"""
123+
series = pd.Series([1, 2, 3], dtype=dtype)
124+
assert series.dtype == dtype
125+
result = _to_numpy(series)
126+
_check_result(result, supported)
127+
npt.assert_array_equal(result, series)

0 commit comments

Comments
 (0)