@@ -143,3 +143,54 @@ def test_to_numpy_pandas_series_numpy_dtypes_numeric(dtype, expected_dtype): |
143 | 143 | result = _to_numpy(series) |
144 | 144 | _check_result(result, expected_dtype) |
145 | 145 | npt.assert_array_equal(result, series) |
| 146 | + |
| 147 | + |
| 148 | +@pytest.mark.parametrize( |
| 149 | + ("dtype", "expected_dtype"), |
| 150 | + [ |
| 151 | + pytest.param(pd.Int8Dtype(), np.int8, id="Int8"), |
| 152 | + pytest.param(pd.Int16Dtype(), np.int16, id="Int16"), |
| 153 | + pytest.param(pd.Int32Dtype(), np.int32, id="Int32"), |
| 154 | + pytest.param(pd.Int64Dtype(), np.int64, id="Int64"), |
| 155 | + pytest.param(pd.UInt8Dtype(), np.uint8, id="UInt8"), |
| 156 | + pytest.param(pd.UInt16Dtype(), np.uint16, id="UInt16"), |
| 157 | + pytest.param(pd.UInt32Dtype(), np.uint32, id="UInt32"), |
| 158 | + pytest.param(pd.UInt64Dtype(), np.uint64, id="UInt64"), |
| 159 | + pytest.param(pd.Float32Dtype(), np.float32, id="Float32"), |
| 160 | + pytest.param(pd.Float64Dtype(), np.float64, id="Float64"), |
| 161 | + ], |
| 162 | +) |
| 163 | +def test_to_numpy_pandas_series_pandas_dtypes_numeric(dtype, expected_dtype): |
| 164 | + """ |
| 165 | + Test the _to_numpy function with pandas.Series of pandas numeric dtypes. |
| 166 | + """ |
| 167 | + series = pd.Series([1, 2, 3, 4, 5, 6], dtype=dtype)[::2] # Not C-contiguous |
| 168 | + result = _to_numpy(series) |
| 169 | + _check_result(result, expected_dtype) |
| 170 | + npt.assert_array_equal(result, series) |
| 171 | + |
| 172 | + |
| 173 | +@pytest.mark.parametrize( |
| 174 | + ("dtype", "expected_dtype"), |
| 175 | + [ |
| 176 | + pytest.param(pd.Int8Dtype(), np.float64, id="Int8"), |
| 177 | + pytest.param(pd.Int16Dtype(), np.float64, id="Int16"), |
| 178 | + pytest.param(pd.Int32Dtype(), np.float64, id="Int32"), |
| 179 | + pytest.param(pd.Int64Dtype(), np.float64, id="Int64"), |
| 180 | + pytest.param(pd.UInt8Dtype(), np.float64, id="UInt8"), |
| 181 | + pytest.param(pd.UInt16Dtype(), np.float64, id="UInt16"), |
| 182 | + pytest.param(pd.UInt32Dtype(), np.float64, id="UInt32"), |
| 183 | + pytest.param(pd.UInt64Dtype(), np.float64, id="UInt64"), |
| 184 | + pytest.param(pd.Float32Dtype(), np.float32, id="Float32"), |
| 185 | + pytest.param(pd.Float64Dtype(), np.float64, id="Float64"), |
| 186 | + ], |
| 187 | +) |
| 188 | +def test_to_numpy_pandas_series_pandas_dtypes_numeric_with_na(dtype, expected_dtype): |
| 189 | + """ |
| 190 | + Test the _to_numpy function with pandas.Series of pandas numeric dtypes and NA. |
| 191 | + """ |
| 192 | + series = pd.Series([1, 2, pd.NA, 4, 5, 6], dtype=dtype)[::2] # Not C-contiguous |
| 193 | + assert series.isna().any() |
| 194 | + result = _to_numpy(series) |
| 195 | + _check_result(result, expected_dtype) |
| 196 | + npt.assert_array_equal(result, np.array([1.0, np.nan, 5.0], dtype=expected_dtype)) |