diff --git a/python/cudf_polars/cudf_polars/containers/column.py b/python/cudf_polars/cudf_polars/containers/column.py index a139927acab..49034b5f5c8 100644 --- a/python/cudf_polars/cudf_polars/containers/column.py +++ b/python/cudf_polars/cudf_polars/containers/column.py @@ -32,12 +32,23 @@ def __init__(self, column: plc.Column, name: str): self.order = plc.types.Order.ASCENDING self.null_order = plc.types.NullOrder.BEFORE - def rename(self, name: str) -> Column: - """Return a new column sharing data with a new name.""" - return type(self)(self.obj, name).sorted_like(self) - def sorted_like(self, like: Column, /) -> Self: - """Copy sortedness properties from a column onto self.""" + """ + Copy sortedness properties from a column onto self. + + Parameters + ---------- + like + The column to copy sortedness metadata from. + + Returns + ------- + Self with metadata set. + + See Also + -------- + set_sorted + """ return self.set_sorted( is_sorted=like.is_sorted, order=like.order, null_order=like.null_order ) @@ -70,9 +81,22 @@ def set_sorted( self.null_order = null_order return self - def copy(self) -> Self: - """Return a shallow copy of the column.""" - return type(self)(self.obj, self.name).sorted_like(self) + def copy(self, *, new_name: str | None = None) -> Self: + """ + Return a shallow copy of the column. + + Parameters + ---------- + new_name + Optional new name for the copied column. + + Returns + ------- + New column sharing data with self. + """ + return type(self)( + self.obj, self.name if new_name is None else new_name + ).sorted_like(self) def mask_nans(self) -> Self: """Return a copy of self with nans masked out.""" diff --git a/python/cudf_polars/cudf_polars/containers/dataframe.py b/python/cudf_polars/cudf_polars/containers/dataframe.py index 0762724d555..2ed4298e993 100644 --- a/python/cudf_polars/cudf_polars/containers/dataframe.py +++ b/python/cudf_polars/cudf_polars/containers/dataframe.py @@ -139,7 +139,7 @@ def replace_columns(self, *columns: Column) -> Self: def rename_columns(self, mapping: Mapping[str, str]) -> Self: """Rename some columns.""" return type(self)( - [c.rename(mapping.get(c.name, c.name)) for c in self.columns], self.scalars + [c.copy(new_name=mapping.get(c.name)) for c in self.columns], self.scalars ) def select_columns(self, names: Set[str]) -> list[Column]: