Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nan_as_null not being respected when passing arrow object #14688

Merged
Merged
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
13 changes: 11 additions & 2 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import numpy as np
import pandas as pd
import pyarrow as pa
import pyarrow.compute as pc
from numba import cuda
from typing_extensions import Self

Expand Down Expand Up @@ -2006,11 +2007,19 @@ def as_column(
return col

elif isinstance(arbitrary, (pa.Array, pa.ChunkedArray)):
if isinstance(arbitrary, pa.lib.HalfFloatArray):
if pa.types.is_float16(arbitrary.type):
raise NotImplementedError(
"Type casting from `float16` to `float32` is not "
"yet supported in pyarrow, see: "
"https://issues.apache.org/jira/browse/ARROW-3802"
"https://github.com/apache/arrow/issues/20213"
)
elif (nan_as_null is None or nan_as_null) and pa.types.is_floating(
arbitrary.type
):
arbitrary = pc.if_else(
pc.is_nan(arbitrary),
pa.nulls(len(arbitrary), type=arbitrary.type),
arbitrary,
)
col = ColumnBase.from_arrow(arbitrary)

Expand Down
10 changes: 10 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,16 @@ def test_series_arrow_list_types_roundtrip():
cudf.from_pandas(pdf)


@pytest.mark.parametrize("klass", [cudf.Index, cudf.Series])
@pytest.mark.parametrize(
"data", [pa.array([float("nan")]), pa.chunked_array([[float("nan")]])]
)
def test_nan_as_null_from_arrow_objects(klass, data):
result = klass(data, nan_as_null=True)
expected = klass(pa.array([None], type=pa.float64()))
assert_eq(result, expected)


@pytest.mark.parametrize("reso", ["M", "ps"])
@pytest.mark.parametrize("typ", ["M", "m"])
def test_series_invalid_reso_dtype(reso, typ):
Expand Down