diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 0bc50a521e2..35b062272e7 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -2061,14 +2061,9 @@ def as_column( ) else: pyarrow_array = pa.array(arbitrary, from_pandas=nan_as_null) - if ( - arbitrary.dtype == cudf.dtype("object") - and cudf.dtype(pyarrow_array.type.to_pandas_dtype()) - != cudf.dtype(arbitrary.dtype) - and not is_bool_dtype( - cudf.dtype(pyarrow_array.type.to_pandas_dtype()) - ) - ): + if arbitrary.dtype == cudf.dtype("object") and cudf.dtype( + pyarrow_array.type.to_pandas_dtype() + ) != cudf.dtype(arbitrary.dtype): raise MixedTypeError("Cannot create column with mixed types") if isinstance(pyarrow_array.type, pa.Decimal128Type): pyarrow_type = cudf.Decimal128Dtype.from_arrow( @@ -2458,9 +2453,6 @@ def as_column( and ( cudf.dtype(pyarrow_array.type.to_pandas_dtype()) != cudf.dtype(arbitrary.dtype) - and not is_bool_dtype( - cudf.dtype(pyarrow_array.type.to_pandas_dtype()) - ) ) ): raise MixedTypeError( diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index c297748f7e5..5728ad6139f 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -4029,7 +4029,7 @@ def test_any(data, axis): dtype = None if data else float if np.array(data).ndim <= 1: pdata = pd.Series(data=data, dtype=dtype) - gdata = cudf.Series.from_pandas(pdata) + gdata = cudf.Series(data=data, dtype=dtype) if axis == 1: with pytest.raises(NotImplementedError): @@ -8949,8 +8949,10 @@ def test_agg_for_dataframe_with_string_columns(aggs): "c": pd.Series([2, np.nan, 5.0], index=[2, 3, 4]), }, { - "a": [True, np.nan, True], - "d": pd.Series([False, True, np.nan], index=[0, 1, 3]), + "a": pd.Series([True, None, True], dtype=pd.BooleanDtype()), + "d": pd.Series( + [False, True, None], index=[0, 1, 3], dtype=pd.BooleanDtype() + ), }, ], ) diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index cfa571a0f54..64945e8a3ad 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -2205,7 +2205,7 @@ def test_series_mixed_dtype_error(dtype): @pytest.mark.parametrize("index", [None, [10, 20, 30]]) def test_series_contains(data, index): ps = pd.Series(data, index=index) - gs = cudf.from_pandas(ps) + gs = cudf.Series(data, index=index) assert_eq(1 in ps, 1 in gs) assert_eq(10 in ps, 10 in gs) @@ -2326,3 +2326,13 @@ def test_series_count_invalid_param(): s = cudf.Series([], dtype="float64") with pytest.raises(TypeError): s.count(skipna=True) + + +def test_bool_series_mixed_dtype_error(): + ps = pd.Series([True, False, None]) + # ps now has `object` dtype, which + # isn't supported by `cudf`. + with pytest.raises(TypeError): + cudf.Series(ps) + with pytest.raises(TypeError): + cudf.from_pandas(ps)