class_docstr: pandas-on-Spark specific features for DataFrame.
docstr: Attach a column to be used as an identifier of rows similar to the default index.
  
  See also `Default Index type
  <https://spark.apache.org/docs/latest/api/python/user_guide/pandas_on_spark/options.html#default-index-type>`_.
  
  Parameters
  ----------
  id_type : string
      The id type.
  
      - 'sequence' : a sequence that increases one by one.
  
        .. note:: this uses Spark's Window without specifying partition specification.
            This leads to moving all data into a single partition in a single machine and
            could cause serious performance degradation.
            Avoid this method with very large datasets.
  
      - 'distributed-sequence' : a sequence that increases one by one,
        by group-by and group-map approach in a distributed manner.
      - 'distributed' : a monotonically increasing sequence simply by using PySpark’s
        monotonically_increasing_id function in a fully distributed manner.
  
  column : string or tuple of string
      The column name.
  
  Returns
  -------
  DataFrame
      The DataFrame attached the column.
  
  Examples
  --------
  >>> df = ps.DataFrame({"x": ['a', 'b', 'c']})
  >>> df.pandas_on_spark.attach_id_column(id_type="sequence", column="id")
     x  id
  0  a   0
  1  b   1
  2  c   2
  
  >>> df.pandas_on_spark.attach_id_column(id_type="distributed-sequence", column=0)
     x  0
  0  a  0
  1  b  1
  2  c  2
  
  >>> df.pandas_on_spark.attach_id_column(id_type="distributed", column=0.0)
  ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
     x  0.0
  0  a  ...
  1  b  ...
  2  c  ...
  
  For multi-index columns:
  
  >>> df = ps.DataFrame({("x", "y"): ['a', 'b', 'c']})
  >>> df.pandas_on_spark.attach_id_column(id_type="sequence", column=("id-x", "id-y"))
     x id-x
     y id-y
  0  a    0
  1  b    1
  2  c    2
  
  >>> df.pandas_on_spark.attach_id_column(id_type="distributed-sequence", column=(0, 1.0))
     x   0
     y 1.0
  0  a   0
  1  b   1
  2  c   2
docstr_tok: ["Attach","a","column","to","be","used","as","an","identifier","of","rows","similar","to","the","default","index",".","See","also","`","Default","Index","type","<","https",":","\/\/spark.apache.org\/docs\/latest\/api\/python\/user_guide\/pandas_on_spark\/options.html","#","default-index-type",">","`","_",".","Parameters","--","--","--","--","--","id_type",":","string","The","id","type",".","-","'sequence","'",":","a","sequence","that","increases","one","by","one",".","..","note",":",":","this","uses","Spark","'s","Window","without","specifying","partition","specification",".","This","leads","to","moving","all","data","into","a","single","partition","in","a","single","machine","and","could","cause","serious","performance","degradation",".","Avoid","this","method","with","very","large","datasets",".","-","'distributed-sequence","'",":","a","sequence","that","increases","one","by","one",",","by","group-by","and","group-map","approach","in","a","distributed","manner",".","-","'distributed","'",":","a","monotonically","increasing","sequence","simply","by","using","PySpark","\u2019","s","monotonically_increasing_id","function","in","a","fully","distributed","manner",".","column",":","string","or","tuple","of","string","The","column","name",".","Returns","--","--","--","-","DataFrame","The","DataFrame","attached","the","column",".","Examples","--","--","--","--",">",">",">","df","=","ps.DataFrame","(","{","``","x","''",":","[","'","a","'",",","'","b","'",",","'","c","'","]","}",")",">",">",">","df.pandas_on_spark.attach_id_column","(","id_type=","''","sequence","''",",","column=","''","id","''",")","x","id","0","a","0","1","b","1","2","c","2",">",">",">","df.pandas_on_spark.attach_id_column","(","id_type=","''","distributed-sequence","''",",","column=0",")","x","0","0","a","0","1","b","1","2","c","2",">",">",">","df.pandas_on_spark.attach_id_column","(","id_type=","''","distributed","''",",","column=0.0",")","...","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","x","0.0","0","a","...","1","b","...","2","c","...","For","multi-index","columns",":",">",">",">","df","=","ps.DataFrame","(","{","(","``","x","''",",","``","y","''",")",":","[","'","a","'",",","'","b","'",",","'","c","'","]","}",")",">",">",">","df.pandas_on_spark.attach_id_column","(","id_type=","''","sequence","''",",","column=","(","``","id-x","''",",","``","id-y","''",")",")","x","id-x","y","id-y","0","a","0","1","b","1","2","c","2",">",">",">","df.pandas_on_spark.attach_id_column","(","id_type=","''","distributed-sequence","''",",","column=","(","0",",","1.0",")",")","x","0","y","1.0","0","a","0","1","b","1","2","c","2"]
code: def attach_id_column(self, id_type: str, column: Name) -> "DataFrame":
      """
      Attach a column to be used as an identifier of rows similar to the default index.
  
      See also `Default Index type
      <https://spark.apache.org/docs/latest/api/python/user_guide/pandas_on_spark/options.html#default-index-type>`_.
  
      Parameters
      ----------
      id_type : string
          The id type.
  
          - 'sequence' : a sequence that increases one by one.
  
            .. note:: this uses Spark's Window without specifying partition specification.
                This leads to moving all data into a single partition in a single machine and
                could cause serious performance degradation.
                Avoid this method with very large datasets.
  
          - 'distributed-sequence' : a sequence that increases one by one,
            by group-by and group-map approach in a distributed manner.
          - 'distributed' : a monotonically increasing sequence simply by using PySpark’s
            monotonically_increasing_id function in a fully distributed manner.
  
      column : string or tuple of string
          The column name.
  
      Returns
      -------
      DataFrame
          The DataFrame attached the column.
  
      Examples
      --------
      >>> df = ps.DataFrame({"x": ['a', 'b', 'c']})
      >>> df.pandas_on_spark.attach_id_column(id_type="sequence", column="id")
         x  id
      0  a   0
      1  b   1
      2  c   2
  
      >>> df.pandas_on_spark.attach_id_column(id_type="distributed-sequence", column=0)
         x  0
      0  a  0
      1  b  1
      2  c  2
  
      >>> df.pandas_on_spark.attach_id_column(id_type="distributed", column=0.0)
      ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
         x  0.0
      0  a  ...
      1  b  ...
      2  c  ...
  
      For multi-index columns:
  
      >>> df = ps.DataFrame({("x", "y"): ['a', 'b', 'c']})
      >>> df.pandas_on_spark.attach_id_column(id_type="sequence", column=("id-x", "id-y"))
         x id-x
         y id-y
      0  a    0
      1  b    1
      2  c    2
  
      >>> df.pandas_on_spark.attach_id_column(id_type="distributed-sequence", column=(0, 1.0))
         x   0
         y 1.0
      0  a   0
      1  b   1
      2  c   2
      """
      from pyspark.pandas.frame import DataFrame
  
      if id_type == "sequence":
          attach_func = InternalFrame.attach_sequence_column
      elif id_type == "distributed-sequence":
          attach_func = InternalFrame.attach_distributed_sequence_column
      elif id_type == "distributed":
          attach_func = InternalFrame.attach_distributed_column
      else:
          raise ValueError(
              "id_type should be one of 'sequence', 'distributed-sequence' and 'distributed'"
          )
  
      assert is_name_like_value(column, allow_none=False), column
      if not is_name_like_tuple(column):
          column = (column,)
  
      internal = self._psdf._internal
  
      if len(column) != internal.column_labels_level:
          raise ValueError(
              "The given column `{}` must be the same length as the existing columns.".format(
                  column
              )
          )
      elif column in internal.column_labels:
          raise ValueError(
              "The given column `{}` already exists.".format(
                  name_like_string(column)
              )
          )
  
      # Make sure the underlying Spark column names are the form of
      # `name_like_string(column_label)`.
      sdf = internal.spark_frame.select(
          [
              scol.alias(SPARK_INDEX_NAME_FORMAT(i))
              for i, scol in enumerate(internal.index_spark_columns)
          ]
          + [
              scol.alias(name_like_string(label))
              for scol, label in zip(
                  internal.data_spark_columns, internal.column_labels
              )
          ]
      )
      sdf = attach_func(sdf, name_like_string(column))
  
      return DataFrame(
          InternalFrame(
              spark_frame=sdf,
              index_spark_columns=[
                  scol_for(sdf, SPARK_INDEX_NAME_FORMAT(i))
                  for i in range(internal.index_level)
              ],
              index_names=internal.index_names,
              index_fields=internal.index_fields,
              column_labels=internal.column_labels + [column],
              data_spark_columns=(
                  [
                      scol_for(sdf, name_like_string(label))
                      for label in internal.column_labels
                  ]
                  + [scol_for(sdf, name_like_string(column))]
              ),
              data_fields=internal.data_fields
              + [
                  InternalField.from_struct_field(
                      StructField(
                          name_like_string(column),
                          LongType(),
                          nullable=False,
                      )
                  )
              ],
              column_label_names=internal.column_label_names,
          ).resolved_copy
      )
  
imports: import inspect
  from typing import Any, Callable, Optional, Tuple, Union, TYPE_CHECKING, cast, List
  from types import FunctionType
  import numpy
  import pandas
  from pyspark.sql import functions
  from pyspark.sql.functions import pandas_udf
  from pyspark.sql.types import DataType, LongType, StructField, StructType
  from pyspark.pandas._typing import DataFrameOrSeries, Name
  from pyspark.pandas.internal import InternalField, InternalFrame, SPARK_INDEX_NAME_FORMAT, SPARK_DEFAULT_SERIES_NAME, SPARK_INDEX_NAME_PATTERN
  from pyspark.pandas.typedef import infer_return_type, DataFrameType, ScalarType, SeriesType
  from pyspark.pandas.utils import is_name_like_value, is_name_like_tuple, name_like_string, scol_for, verify_temp_column_name, log_advice
label_desc: Use image node_id 2 for calling the PandasOnSparkFrameMethods obj's underlying member method code with example usage: obj.attach_id_column(id_type, column) and returns: DataFrame