From 1cc2577a9cb83edd3fcad06f2bf0a5b7b64d05aa Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Thu, 3 Aug 2023 16:23:34 -0700 Subject: [PATCH] Raise an error when mixed types are constructed --- 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)