code: def to_csv(
      df,
      path_or_buf=None,
      sep=",",
      na_rep="",
      columns=None,
      header=True,
      index=True,
      encoding=None,
      compression=None,
      lineterminator="\n",
      chunksize=None,
      storage_options=None,
  ):
      """{docstring}"""
  
      if not isinstance(sep, str):
          raise TypeError(
              f'"sep" must be string, not {type(sep).__name__}'
          )
      elif len(sep) > 1:
          raise TypeError('"sep" must be a 1-character string')
  
      if encoding and encoding != "utf-8":
          error_msg = (
              f"Encoding {encoding} is not supported. "
              + "Currently, only utf-8 encoding is supported."
          )
          raise NotImplementedError(error_msg)
  
      if compression:
          error_msg = "Writing compressed csv is not currently supported in cudf"
          raise NotImplementedError(error_msg)
  
      return_as_string = False
      if path_or_buf is None:
          path_or_buf = StringIO()
          return_as_string = True
  
      path_or_buf = ioutils.get_writer_filepath_or_buffer(
          path_or_data=path_or_buf,
          mode="w",
          storage_options=storage_options,
      )
  
      if columns is not None:
          try:
              df = df[columns]
          except KeyError:
              raise NameError(
                  "Dataframe doesn't have the labels provided in columns"
              )
  
      for col in df._data.columns:
          if isinstance(col, cudf.core.column.ListColumn):
              raise NotImplementedError(
                  "Writing to csv format is not yet supported with "
                  "list columns."
              )
          elif isinstance(col, cudf.core.column.StructColumn):
              raise NotImplementedError(
                  "Writing to csv format is not yet supported with "
                  "Struct columns."
              )
  
      # TODO: Need to typecast categorical columns to the underlying
      # categories dtype to write the actual data to csv. Remove this
      # workaround once following issue is fixed:
      # https://github.com/rapidsai/cudf/issues/6661
      if any(
          isinstance(col, cudf.core.column.CategoricalColumn)
          for col in df._data.columns
      ) or isinstance(df.index, cudf.CategoricalIndex):
          df = df.copy(deep=False)
          for col_name, col in df._data.items():
              if isinstance(col, cudf.core.column.CategoricalColumn):
                  df._data[col_name] = col.astype(col.categories.dtype)
  
          if isinstance(df.index, cudf.CategoricalIndex):
              df.index = df.index.astype(df.index.categories.dtype)
  
      rows_per_chunk = chunksize if chunksize else len(df)
  
      if ioutils.is_fsspec_open_file(path_or_buf):
          with path_or_buf as file_obj:
              file_obj = ioutils.get_IOBase_writer(file_obj)
              libcudf.csv.write_csv(
                  df,
                  path_or_buf=file_obj,
                  sep=sep,
                  na_rep=na_rep,
                  header=header,
                  lineterminator=lineterminator,
                  rows_per_chunk=rows_per_chunk,
                  index=index,
              )
      else:
          libcudf.csv.write_csv(
              df,
              path_or_buf=path_or_buf,
              sep=sep,
              na_rep=na_rep,
              header=header,
              lineterminator=lineterminator,
              rows_per_chunk=rows_per_chunk,
              index=index,
          )
  
      if return_as_string:
          path_or_buf.seek(0)
          return path_or_buf.read()
  
file_path: cudf/python/cudf/cudf/io/csv.py
imports: from collections import abc
  from io import BytesIO, StringIO
  import numpy
  from pyarrow.lib import NativeFile
  import cudf
  from cudf import _lib
  from cudf.api.types import is_scalar
  from cudf.utils import ioutils
  from cudf.utils.dtypes import _maybe_convert_to_default_type
  from cudf.utils.nvtx_annotation import _cudf_nvtx_annotate
label_desc: Use image node_id 2 for calling a global function with example usage: to_csv(df, path_or_buf, sep, na_rep, columns, header, index, encoding, compression, lineterminator, chunksize, storage_options) and returns: path_or_buf