|
4 | 4 |
|
5 | 5 | import numpy as np
|
6 | 6 | import numpy.testing as npt
|
| 7 | +import pandas as pd |
7 | 8 | import pytest
|
8 | 9 | from pygmt.clib.conversion import _to_numpy
|
9 | 10 | from pygmt.clib.session import DTYPES
|
@@ -80,3 +81,47 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, supported):
|
80 | 81 | result = _to_numpy(array)
|
81 | 82 | _check_result(result, supported)
|
82 | 83 | 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