From 4dca1873a8aed5211a1b6339b632dfe53b14f605 Mon Sep 17 00:00:00 2001 From: Asthenia0412 Date: Wed, 14 Oct 2026 08:13:07 +0000 Subject: [PATCH] GH-51696: Remove stale float16 guard in from_dataframe The guard rejecting float16 columns with NaN values was added because pc.is_nan didn't have a float16 kernel at the time. PR #46866 (GH-45083) later added that kernel, making this guard obsolete. Removing the guard allows pandas float16 DataFrames to be imported via from_dataframe() properly. Also update test_pandas_to_pyarrow_float16_with_missing to verify the correct behavior instead of expecting NotImplementedError. --- python/pyarrow/interchange/from_dataframe.py | 24 +++++++------------ .../tests/interchange/test_conversion.py | 9 ++++--- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/python/pyarrow/interchange/from_dataframe.py b/python/pyarrow/interchange/from_dataframe.py index dba92a3aac42..11a5fd8b94e3 100644 --- a/python/pyarrow/interchange/from_dataframe.py +++ b/python/pyarrow/interchange/from_dataframe.py @@ -546,21 +546,15 @@ def validity_buffer_nan_sentinel( "required which is forbidden by allow_copy=False" ) - if kind == DtypeKind.FLOAT and bit_width == 16: - # 'pyarrow.compute.is_nan' kernel not yet implemented - # for float16 - raise NotImplementedError( - f"{data_type} with {null_kind} is not yet supported.") - else: - pyarrow_data = pa.Array.from_buffers( - data_dtype, - length, - [None, data_pa_buffer], - offset=offset, - ) - mask = pc.is_nan(pyarrow_data) - mask = pc.invert(mask) - return mask.buffers()[1] + pyarrow_data = pa.Array.from_buffers( + data_dtype, + length, + [None, data_pa_buffer], + offset=offset, + ) + mask = pc.is_nan(pyarrow_data) + mask = pc.invert(mask) + return mask.buffers()[1] # Check for sentinel values elif null_kind == ColumnNullType.USE_SENTINEL: diff --git a/python/pyarrow/tests/interchange/test_conversion.py b/python/pyarrow/tests/interchange/test_conversion.py index cc105178ad87..b083870437b9 100644 --- a/python/pyarrow/tests/interchange/test_conversion.py +++ b/python/pyarrow/tests/interchange/test_conversion.py @@ -319,14 +319,13 @@ def test_pandas_to_pyarrow_with_missing(np_float_str): @pytest.mark.pandas def test_pandas_to_pyarrow_float16_with_missing(): - # np.float16 errors if ps.is_nan is used - # pyarrow.lib.ArrowNotImplementedError: Function 'is_nan' has no kernel - # matching input types (halffloat) + # pc.is_nan has supported float16 kernel since PR #46866 (GH-45083) np_array = np.array([0, np.nan, 2], dtype=np.float16) df = pd.DataFrame({"a": np_array}) + expected = pa.table({"a": pa.array(np_array, from_pandas=True)}) - with pytest.raises(NotImplementedError): - pi.from_dataframe(df) + result = pi.from_dataframe(df) + assert result.equals(expected) @pytest.mark.numpy