Skip to content

Commit

Permalink
Consolidate cudf object handling in as_column (#14754)
Browse files Browse the repository at this point in the history
Since these paths are very similar, consolidating these paths and returning early for this case

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #14754
  • Loading branch information
mroeschke authored Jan 19, 2024
1 parent 3f7983e commit 09b6e45
Showing 1 changed file with 9 additions and 13 deletions.
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 @@ -1871,6 +1871,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 @@ -1907,22 +1908,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

0 comments on commit 09b6e45

Please sign in to comment.