Skip to content
/ cudf Public
forked from rapidsai/cudf

Commit

Permalink
Implement astype utility method on Columns
Browse files Browse the repository at this point in the history
This returns a pylibcudf column, so no metadata, which is awkward. We
will change that when rapidsai#16272 is fixed.
  • Loading branch information
wence- committed Aug 29, 2024
1 parent bed1dcc commit 2b5f2cc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions python/cudf_polars/cudf_polars/containers/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ def sorted_like(self, like: Column, /) -> Self:
is_sorted=like.is_sorted, order=like.order, null_order=like.null_order
)

# TODO: Return Column once #16272 is fixed.
def astype(self, dtype: plc.DataType) -> plc.Column:
"""
Return the backing column as the requested dtype.
Parameters
----------
dtype
Datatype to cast to.
Returns
-------
Column of requested type.
Raises
------
RuntimeError
If the cast is unsupported.
Notes
-----
This only produces a copy if the requested dtype doesn't match
the current one.
"""
if self.obj.type() != dtype:
return plc.unary.cast(self.obj, dtype)
return self.obj

def copy_metadata(self, from_: pl.Series, /) -> Self:
"""
Copy metadata from a host series onto self.
Expand Down

0 comments on commit 2b5f2cc

Please sign in to comment.