rename_columns#

Dataset.rename_columns(names: List[str] | Dict[str, str], *, concurrency: int | Tuple[int, int] | Tuple[int, int, int] | None = None, num_cpus: float | None = None, num_gpus: float | None = None, memory: float | None = None, label_selector: Dict[str, str] | None = None, fallback_strategy: List[Dict[str, Any]] | None = None, max_calls: int | None = None, resources: Dict[str, float] | None = None, accelerator_type: str | None = None, runtime_env: Dict[str, Any] | None = None, **ray_remote_args)[source]#

Rename columns in the dataset.

Examples

>>> import ray
>>> ds = ray.data.read_parquet("s3://anonymous@ray-example-data/iris.parquet")
>>> ds.schema()
Column        Type
------        ----
sepal.length  double
sepal.width   double
petal.length  double
petal.width   double
variety       string

You can pass a dictionary mapping old column names to new column names.

>>> ds.rename_columns({"variety": "category"}).schema()
Column        Type
------        ----
sepal.length  double
sepal.width   double
petal.length  double
petal.width   double
category      string

Or you can pass a list of new column names.

>>> ds.rename_columns(
...     ["sepal_length", "sepal_width", "petal_length", "petal_width", "variety"]
... ).schema()
Column        Type
------        ----
sepal_length  double
sepal_width   double
petal_length  double
petal_width   double
variety       string
Parameters:
  • names (List[str] | Dict[str, str]) – A dictionary that maps old column names to new column names, or a list of new column names.

  • concurrency (int | Tuple[int, int] | Tuple[int, int, int] | None) – The maximum number of Ray workers to use concurrently.

  • num_cpus (float | None) – The number of CPUs to reserve for each worker.

  • num_gpus (float | None) – The number of GPUs to reserve for each worker.

  • memory (float | None) – The heap memory in bytes to reserve for each worker.

  • label_selector (Dict[str, str] | None) – Labels required on the node where each worker runs.

  • fallback_strategy (List[Dict[str, Any]] | None) – Alternative label requirements that Ray tries in order when label_selector can’t be satisfied.

  • max_calls (int | None) – The maximum number of calls a task worker handles before exiting. This option only applies to task workers.

  • resources (Dict[str, float] | None) – Custom resources to reserve for each worker, expressed as a mapping from resource name to quantity.

  • accelerator_type (str | None) – The accelerator type required on the node where each worker runs.

  • runtime_env (Dict[str, Any] | None) – The runtime environment to use for each worker.

  • **ray_remote_args – Additional resource requirements to request from Ray (e.g., num_gpus=1 to request GPUs for the map tasks). See ray.remote() for details. This argument is deprecated and will be removed in Ray 2.64.

Returns:

A new Dataset with the specified columns renamed.