Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions python/pyarrow/interchange/from_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions python/pyarrow/tests/interchange/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's better to just removetest_pandas_to_pyarrow_float16_with_missing test and make sure pc.is_nan on float16 is tested where all other types are tested.

# 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
Expand Down
Loading