diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 705862c502a..96b76b87ac4 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -1873,6 +1873,7 @@ def as_column( If None (default), treats NaN values in arbitrary as null if there is no mask passed along with it. If True, combines the mask and NaNs to form a new validity mask. If False, leaves NaN values as is. + Only applies when arbitrary is not a cudf object (Index, Series, Column). dtype : optional Optionally typecast the constructed Column to the given dtype. @@ -1909,22 +1910,17 @@ def as_column( f'i{cudf.get_option("default_integer_bitwidth")//8}' ) if dtype is not None: - column = column.astype(dtype) + return column.astype(dtype) return column - elif isinstance(arbitrary, ColumnBase): + elif isinstance(arbitrary, (ColumnBase, cudf.Series, cudf.BaseIndex)): + # Ignoring nan_as_null per the docstring + if isinstance(arbitrary, cudf.Series): + arbitrary = arbitrary._column + elif isinstance(arbitrary, cudf.BaseIndex): + arbitrary = arbitrary._values if dtype is not None: return arbitrary.astype(dtype) - else: - return arbitrary - elif isinstance(arbitrary, cudf.Series): - data = arbitrary._column - if dtype is not None: - data = data.astype(dtype) - elif isinstance(arbitrary, cudf.BaseIndex): - data = arbitrary._values - if dtype is not None: - data = data.astype(dtype) - + return arbitrary elif hasattr(arbitrary, "__cuda_array_interface__"): desc = arbitrary.__cuda_array_interface__ shape = desc["shape"]