Skip to content

Commit

Permalink
Raise error when mixed types are being constructed (#13816)
Browse files Browse the repository at this point in the history
This PR raises error when a mixed type data is being constructed instead of type-casting `nan` values to string nans (`'nan'`)

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #13816
  • Loading branch information
galipremsagar authored Aug 4, 2023
1 parent 15cc501 commit 073bf83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,9 +2161,7 @@ def as_column(
if dtype is not None:
data = data.astype(dtype)
elif arb_dtype.kind in ("O", "U"):
data = as_column(
pa.Array.from_pandas(arbitrary), dtype=arbitrary.dtype
)
data = as_column(pa.array(arbitrary), dtype=arbitrary.dtype)
# There is no cast operation available for pa.Array from int to
# str, Hence instead of handling in pa.Array block, we
# will have to type-cast here.
Expand Down Expand Up @@ -2422,7 +2420,7 @@ def _construct_array(
if (
dtype is None
and not cudf._lib.scalar._is_null_host_scalar(arbitrary)
and infer_dtype(arbitrary)
and infer_dtype(arbitrary, skipna=False)
in (
"mixed",
"mixed-integer",
Expand Down
5 changes: 5 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2219,3 +2219,8 @@ def __getitem__(self, key):

with pytest.raises(TypeError):
cudf.Series(A())


def test_series_constructor_error_mixed_type():
with pytest.raises(pa.ArrowTypeError):
cudf.Series(["abc", np.nan, "123"], nan_as_null=False)

0 comments on commit 073bf83

Please sign in to comment.