@@ -171,3 +171,35 @@ def test_to_numpy_pandas_series_pandas_dtypes_numeric(dtype, supported):
171171 result = _to_numpy (series )
172172 _check_result (result , supported )
173173 npt .assert_array_equal (result , series )
174+
175+
176+ @pytest .mark .parametrize (
177+ ("dtype" , "supported" ),
178+ [
179+ pytest .param (pd .Int8Dtype (), True , id = "Int8" ),
180+ pytest .param (pd .Int16Dtype (), True , id = "Int16" ),
181+ pytest .param (pd .Int32Dtype (), True , id = "Int32" ),
182+ pytest .param (pd .Int64Dtype (), True , id = "Int64" ),
183+ pytest .param (pd .UInt8Dtype (), True , id = "UInt8" ),
184+ pytest .param (pd .UInt16Dtype (), True , id = "UInt16" ),
185+ pytest .param (pd .UInt32Dtype (), True , id = "UInt32" ),
186+ pytest .param (pd .UInt64Dtype (), True , id = "UInt64" ),
187+ pytest .param (pd .Float32Dtype (), True , id = "Float32" ),
188+ pytest .param (pd .Float64Dtype (), True , id = "Float64" ),
189+ ],
190+ )
191+ def test_to_numpy_pandas_series_pandas_dtypes_numeric_with_na (dtype , supported ):
192+ """
193+ Test the _to_numpy function with pandas.Series of pandas numeric dtypes and NA.
194+ """
195+ series = pd .Series ([1 , pd .NA , 3 ], dtype = dtype )
196+ assert series .dtype == dtype
197+ result = _to_numpy (series )
198+ _check_result (result , supported )
199+ # Integer dtypes with missing values are cast to NumPy float64 dtype, and Float
200+ # dtypes with missing values are cast to NumPy float32/float64 dtype.
201+ # np.NaN is used as missing value indicator.
202+ expected_dtype = np .float64 if series .dtype .kind in "iu" else series .dtype .type
203+ npt .assert_array_equal (
204+ result , np .array ([1.0 , np .nan , 3.0 ], dtype = expected_dtype ), strict = True
205+ )
0 commit comments