Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate cudf object handling in as_column #14754

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"]
Expand Down