From 073bf83b3b8e74826a036fafb2837afe9d4e09f3 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Fri, 4 Aug 2023 10:02:18 -0500 Subject: [PATCH] Raise error when mixed types are being constructed (#13816) 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: https://github.com/rapidsai/cudf/pull/13816 --- python/cudf/cudf/core/column/column.py | 6 ++---- python/cudf/cudf/tests/test_series.py | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index da3d04c15c0..57f6c80fb05 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -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. @@ -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", diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index 58eaebae925..6b009d7e913 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -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)