@@ -187,7 +187,12 @@ def test_to_numpy_pandas_series_pyarrow_dtypes_numeric(dtype, expected_dtype):
187
187
"""
188
188
Test the _to_numpy function with pandas.Series of PyArrow numeric dtypes.
189
189
"""
190
- series = pd .Series ([1 , 2 , 3 , 4 , 5 , 6 ], dtype = dtype )[::2 ] # Not C-contiguous
190
+ data = [1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 ]
191
+ if dtype == "float16[pyarrow]" and Version (pd .__version__ ) < Version ("2.2" ):
192
+ # float16 needs special handling for pandas < 2.2.
193
+ # Example from https://arrow.apache.org/docs/python/generated/pyarrow.float16.html
194
+ data = np .array (data , dtype = np .float16 )
195
+ series = pd .Series (data , dtype = dtype )[::2 ] # Not C-contiguous
191
196
result = _to_numpy (series )
192
197
_check_result (result , expected_dtype )
193
198
npt .assert_array_equal (result , series )
@@ -214,7 +219,12 @@ def test_to_numpy_pandas_series_pyarrow_dtypes_numeric_with_na(dtype, expected_d
214
219
"""
215
220
Test the _to_numpy function with pandas.Series of PyArrow numeric dtypes and NA.
216
221
"""
217
- series = pd .Series ([1 , 2 , pd .NA , 4 , 5 , 6 ], dtype = dtype )[::2 ]
222
+ data = [1.0 , 2.0 , None , 4.0 , 5.0 , 6.0 ]
223
+ if dtype == "float16[pyarrow]" and Version (pd .__version__ ) < Version ("2.2" ):
224
+ # float16 needs special handling for pandas < 2.2.
225
+ # Example from https://arrow.apache.org/docs/python/generated/pyarrow.float16.html
226
+ data = np .array (data , dtype = np .float16 )
227
+ series = pd .Series (data , dtype = dtype )[::2 ] # Not C-contiguous
218
228
assert series .isna ().any ()
219
229
result = _to_numpy (series )
220
230
_check_result (result , expected_dtype )
0 commit comments