code: def __init__(
      self,
      obj,
      path_or_buf=None,
      sep=",",
      na_rep="",
      float_format=None,
      cols=None,
      header=True,
      index=True,
      index_label=None,
      mode="w",
      nanRep=None,
      encoding=None,
      compression="infer",
      quoting=None,
      line_terminator="\n",
      chunksize=None,
      tupleize_cols=False,
      quotechar='"',
      date_format=None,
      doublequote=True,
      escapechar=None,
      decimal=".",
  ):
      self.obj = obj
  
      if path_or_buf is None:
          path_or_buf = StringIO()
  
      self.path_or_buf, _, _, _ = get_filepath_or_buffer(
          path_or_buf,
          encoding=encoding,
          compression=compression,
          mode=mode,
      )
      self.sep = sep
      self.na_rep = na_rep
      self.float_format = float_format
      self.decimal = decimal
  
      self.header = header
      self.index = index
      self.index_label = index_label
      self.mode = mode
      if encoding is None:
          encoding = "ascii" if compat.PY2 else "utf-8"
      self.encoding = encoding
      self.compression = _infer_compression(
          self.path_or_buf, compression
      )
  
      if quoting is None:
          quoting = csvlib.QUOTE_MINIMAL
      self.quoting = quoting
  
      if quoting == csvlib.QUOTE_NONE:
          # prevents crash in _csv
          quotechar = None
      self.quotechar = quotechar
  
      self.doublequote = doublequote
      self.escapechar = escapechar
  
      self.line_terminator = line_terminator or os.linesep
  
      self.date_format = date_format
  
      self.tupleize_cols = tupleize_cols
      self.has_mi_columns = (
          isinstance(obj.columns, ABCMultiIndex)
          and not self.tupleize_cols
      )
  
      # validate mi options
      if self.has_mi_columns:
          if cols is not None:
              raise TypeError(
                  "cannot specify cols with a MultiIndex on the "
                  "columns"
              )
  
      if cols is not None:
          if isinstance(cols, ABCIndexClass):
              cols = cols.to_native_types(
                  na_rep=na_rep,
                  float_format=float_format,
                  date_format=date_format,
                  quoting=self.quoting,
              )
          else:
              cols = list(cols)
          self.obj = self.obj.loc[:, cols]
  
      # update columns to include possible multiplicity of dupes
      # and make sure sure cols is just a list of labels
      cols = self.obj.columns
      if isinstance(cols, ABCIndexClass):
          cols = cols.to_native_types(
              na_rep=na_rep,
              float_format=float_format,
              date_format=date_format,
              quoting=self.quoting,
          )
      else:
          cols = list(cols)
  
      # save it
      self.cols = cols
  
      # preallocate data 2d list
      self.blocks = self.obj._data.blocks
      ncols = sum(b.shape[0] for b in self.blocks)
      self.data = [None] * ncols
  
      if chunksize is None:
          chunksize = (100000 // (len(self.cols) or 1)) or 1
      self.chunksize = int(chunksize)
  
      self.data_index = obj.index
      if (
          isinstance(
              self.data_index, (ABCDatetimeIndex, ABCPeriodIndex)
          )
          and date_format is not None
      ):
          from pandas import Index
  
          self.data_index = Index(
              [
                  x.strftime(date_format) if notna(x) else ""
                  for x in self.data_index
              ]
          )
  
      self.nlevels = getattr(self.data_index, "nlevels", 1)
      if not index:
          self.nlevels = 0
  
file_path: catboost/contrib/python/pandas/py2/pandas/io/formats/csvs.py
imports: from __future__ import print_function
  import csv
  import os
  import warnings
  from zipfile import ZipFile
  import numpy
  from pandas._libs import writers
  from pandas.compat import StringIO, range, zip
  from pandas.core.dtypes.generic import ABCDatetimeIndex, ABCIndexClass, ABCMultiIndex, ABCPeriodIndex
  from pandas.core.dtypes.missing import notna
  from pandas import compat
  from pandas.io.common import UnicodeWriter, _get_handle, _infer_compression, get_filepath_or_buffer
label_desc: Use image node_id 1 to create a new CSVFormatter object from inherited base classes: object with example: obj = CSVFormatter(obj, path_or_buf, sep, na_rep, float_format, cols, header, index, index_label, mode, nanRep, encoding, compression, quoting, line_terminator, chunksize, tupleize_cols, quotechar, date_format, doublequote, escapechar, decimal)