Skip to content

Commit 29087dd

Browse files
committed
Add tests for panda.Series with pandas numeric dtypes
1 parent 8bc2f56 commit 29087dd

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,53 @@ def test_to_numpy_pandas_series_numpy_dtypes_numeric(dtype, expected_dtype):
157157
result = _to_numpy(series)
158158
_check_result(result, expected_dtype)
159159
npt.assert_array_equal(result, series)
160+
161+
162+
@pytest.mark.parametrize(
163+
("dtype", "expected_dtype"),
164+
[
165+
pytest.param(pd.Int8Dtype(), np.int8, id="Int8"),
166+
pytest.param(pd.Int16Dtype(), np.int16, id="Int16"),
167+
pytest.param(pd.Int32Dtype(), np.int32, id="Int32"),
168+
pytest.param(pd.Int64Dtype(), np.int64, id="Int64"),
169+
pytest.param(pd.UInt8Dtype(), np.uint8, id="UInt8"),
170+
pytest.param(pd.UInt16Dtype(), np.uint16, id="UInt16"),
171+
pytest.param(pd.UInt32Dtype(), np.uint32, id="UInt32"),
172+
pytest.param(pd.UInt64Dtype(), np.uint64, id="UInt64"),
173+
pytest.param(pd.Float32Dtype(), np.float32, id="Float32"),
174+
pytest.param(pd.Float64Dtype(), np.float64, id="Float64"),
175+
],
176+
)
177+
def test_to_numpy_pandas_series_pandas_dtypes_numeric(dtype, expected_dtype):
178+
"""
179+
Test the _to_numpy function with pandas.Series of pandas numeric dtypes.
180+
"""
181+
series = pd.Series([1, 2, 3], dtype=dtype)
182+
result = _to_numpy(series)
183+
_check_result(result, expected_dtype)
184+
npt.assert_array_equal(result, series)
185+
186+
187+
@pytest.mark.parametrize(
188+
("dtype", "expected_dtype"),
189+
[
190+
pytest.param(pd.Int8Dtype(), np.float64, id="Int8"),
191+
pytest.param(pd.Int16Dtype(), np.float64, id="Int16"),
192+
pytest.param(pd.Int32Dtype(), np.float64, id="Int32"),
193+
pytest.param(pd.Int64Dtype(), np.float64, id="Int64"),
194+
pytest.param(pd.UInt8Dtype(), np.float64, id="UInt8"),
195+
pytest.param(pd.UInt16Dtype(), np.float64, id="UInt16"),
196+
pytest.param(pd.UInt32Dtype(), np.float64, id="UInt32"),
197+
pytest.param(pd.UInt64Dtype(), np.float64, id="UInt64"),
198+
pytest.param(pd.Float32Dtype(), np.float32, id="Float32"),
199+
pytest.param(pd.Float64Dtype(), np.float64, id="Float64"),
200+
],
201+
)
202+
def test_to_numpy_pandas_series_pandas_dtypes_numeric_with_na(dtype, expected_dtype):
203+
"""
204+
Test the _to_numpy function with pandas.Series of pandas numeric dtypes and NA.
205+
"""
206+
series = pd.Series([1, pd.NA, 3], dtype=dtype)
207+
result = _to_numpy(series)
208+
_check_result(result, expected_dtype)
209+
npt.assert_array_equal(result, np.array([1.0, np.nan, 3.0], dtype=expected_dtype))

0 commit comments

Comments
 (0)