class_docstr: Accessor object for categorical properties of the Series values.
  
  Examples
  --------
  >>> s = ps.Series(list("abbccc"), dtype="category")
  >>> s  # doctest: +SKIP
  0    a
  1    b
  2    b
  3    c
  4    c
  5    c
  dtype: category
  Categories (3, object): ['a', 'b', 'c']
  
  >>> s.cat.categories
  Index(['a', 'b', 'c'], dtype='object')
  
  >>> s.cat.codes
  0    0
  1    1
  2    1
  3    2
  4    2
  5    2
  dtype: int8
class_docstr_tok: ["Accessor","object","for","categorical","properties","of","the","Series","values",".","Examples","--","--","--","--",">",">",">","s","=","ps.Series","(","list","(","``","abbccc","''",")",",","dtype=","''","category","''",")",">",">",">","s","#","doctest",":","+SKIP","0","a","1","b","2","b","3","c","4","c","5","c","dtype",":","category","Categories","(","3",",","object",")",":","[","'","a","'",",","'","b","'",",","'","c","'","]",">",">",">","s.cat.categories","Index","(","[","'","a","'",",","'","b","'",",","'","c","'","]",",","dtype='object","'",")",">",">",">","s.cat.codes","0","0","1","1","2","1","3","2","4","2","5","2","dtype",":","int8"]
docstr: Set the categories to the specified new_categories.
  
  `new_categories` can include new categories (which will result in
  unused categories) or remove old categories (which results in values
  set to NaN). If `rename==True`, the categories will simply be renamed
  (less or more items than in old categories will result in values set to
  NaN or in unused categories respectively).
  
  This method can be used to perform more than one action of adding,
  removing, and reordering simultaneously and is therefore faster than
  performing the individual steps via the more specialised methods.
  
  On the other hand this methods does not do checks (e.g., whether the
  old categories are included in the new categories on a reorder), which
  can result in surprising changes, for example when using special string
  dtypes, which does not consider a S1 string equal to a single char
  python string.
  
  Parameters
  ----------
  new_categories : Index-like
     The categories in new order.
  ordered : bool, default False
     Whether or not the categorical is treated as an ordered categorical.
     If not given, do not change the ordered information.
  rename : bool, default False
     Whether or not the new_categories should be considered as a rename
     of the old categories or as reordered categories.
  
  Returns
  -------
  Series with reordered categories
  
  Raises
  ------
  ValueError
      If new_categories does not validate as categories
  
  See Also
  --------
  rename_categories : Rename categories.
  reorder_categories : Reorder categories.
  add_categories : Add new categories.
  remove_categories : Remove the specified categories.
  remove_unused_categories : Remove categories which are not used.
  
  Examples
  --------
  >>> s = ps.Series(list("abbccc"), dtype="category")
  >>> s  # doctest: +SKIP
  0    a
  1    b
  2    b
  3    c
  4    c
  5    c
  dtype: category
  Categories (3, object): ['a', 'b', 'c']
  
  >>> s.cat.set_categories(['b', 'c'])  # doctest: +SKIP
  0    NaN
  1      b
  2      b
  3      c
  4      c
  5      c
  dtype: category
  Categories (2, object): ['b', 'c']
  
  >>> s.cat.set_categories([1, 2, 3], rename=True)  # doctest: +SKIP
  0    1
  1    2
  2    2
  3    3
  4    3
  5    3
  dtype: category
  Categories (3, int64): [1, 2, 3]
  
  >>> s.cat.set_categories([1, 2, 3], rename=True, ordered=True)  # doctest: +SKIP
  0    1
  1    2
  2    2
  3    3
  4    3
  5    3
  dtype: category
  Categories (3, int64): [1 < 2 < 3]
docstr_tok: ["Set","the","categories","to","the","specified","new_categories",".","`","new_categories","`","can","include","new","categories","(","which","will","result","in","unused","categories",")","or","remove","old","categories","(","which","results","in","values","set","to","NaN",")",".","If","`","rename==True","`",",","the","categories","will","simply","be","renamed","(","less","or","more","items","than","in","old","categories","will","result","in","values","set","to","NaN","or","in","unused","categories","respectively",")",".","This","method","can","be","used","to","perform","more","than","one","action","of","adding",",","removing",",","and","reordering","simultaneously","and","is","therefore","faster","than","performing","the","individual","steps","via","the","more","specialised","methods",".","On","the","other","hand","this","methods","does","not","do","checks","(","e.g.",",","whether","the","old","categories","are","included","in","the","new","categories","on","a","reorder",")",",","which","can","result","in","surprising","changes",",","for","example","when","using","special","string","dtypes",",","which","does","not","consider","a","S1","string","equal","to","a","single","char","python","string",".","Parameters","--","--","--","--","--","new_categories",":","Index-like","The","categories","in","new","order",".","ordered",":","bool",",","default","False","Whether","or","not","the","categorical","is","treated","as","an","ordered","categorical",".","If","not","given",",","do","not","change","the","ordered","information",".","rename",":","bool",",","default","False","Whether","or","not","the","new_categories","should","be","considered","as","a","rename","of","the","old","categories","or","as","reordered","categories",".","Returns","--","--","--","-","Series","with","reordered","categories","Raises","--","--","--","ValueError","If","new_categories","does","not","validate","as","categories","See","Also","--","--","--","--","rename_categories",":","Rename","categories",".","reorder_categories",":","Reorder","categories",".","add_categories",":","Add","new","categories",".","remove_categories",":","Remove","the","specified","categories",".","remove_unused_categories",":","Remove","categories","which","are","not","used",".","Examples","--","--","--","--",">",">",">","s","=","ps.Series","(","list","(","``","abbccc","''",")",",","dtype=","''","category","''",")",">",">",">","s","#","doctest",":","+SKIP","0","a","1","b","2","b","3","c","4","c","5","c","dtype",":","category","Categories","(","3",",","object",")",":","[","'","a","'",",","'","b","'",",","'","c","'","]",">",">",">","s.cat.set_categories","(","[","'","b","'",",","'","c","'","]",")","#","doctest",":","+SKIP","0","NaN","1","b","2","b","3","c","4","c","5","c","dtype",":","category","Categories","(","2",",","object",")",":","[","'","b","'",",","'","c","'","]",">",">",">","s.cat.set_categories","(","[","1",",","2",",","3","]",",","rename=True",")","#","doctest",":","+SKIP","0","1","1","2","2","2","3","3","4","3","5","3","dtype",":","category","Categories","(","3",",","int64",")",":","[","1",",","2",",","3","]",">",">",">","s.cat.set_categories","(","[","1",",","2",",","3","]",",","rename=True",",","ordered=True",")","#","doctest",":","+SKIP","0","1","1","2","2","2","3","3","4","3","5","3","dtype",":","category","Categories","(","3",",","int64",")",":","[","1","<","2","<","3","]"]
code: def set_categories(
      self,
      new_categories: Union[pd.Index, List],
      ordered: Optional[bool] = None,
      rename: bool = False,
  ) -> Optional["ps.Series"]:
      """
      Set the categories to the specified new_categories.
  
      `new_categories` can include new categories (which will result in
      unused categories) or remove old categories (which results in values
      set to NaN). If `rename==True`, the categories will simply be renamed
      (less or more items than in old categories will result in values set to
      NaN or in unused categories respectively).
  
      This method can be used to perform more than one action of adding,
      removing, and reordering simultaneously and is therefore faster than
      performing the individual steps via the more specialised methods.
  
      On the other hand this methods does not do checks (e.g., whether the
      old categories are included in the new categories on a reorder), which
      can result in surprising changes, for example when using special string
      dtypes, which does not consider a S1 string equal to a single char
      python string.
  
      Parameters
      ----------
      new_categories : Index-like
         The categories in new order.
      ordered : bool, default False
         Whether or not the categorical is treated as an ordered categorical.
         If not given, do not change the ordered information.
      rename : bool, default False
         Whether or not the new_categories should be considered as a rename
         of the old categories or as reordered categories.
  
      Returns
      -------
      Series with reordered categories
  
      Raises
      ------
      ValueError
          If new_categories does not validate as categories
  
      See Also
      --------
      rename_categories : Rename categories.
      reorder_categories : Reorder categories.
      add_categories : Add new categories.
      remove_categories : Remove the specified categories.
      remove_unused_categories : Remove categories which are not used.
  
      Examples
      --------
      >>> s = ps.Series(list("abbccc"), dtype="category")
      >>> s  # doctest: +SKIP
      0    a
      1    b
      2    b
      3    c
      4    c
      5    c
      dtype: category
      Categories (3, object): ['a', 'b', 'c']
  
      >>> s.cat.set_categories(['b', 'c'])  # doctest: +SKIP
      0    NaN
      1      b
      2      b
      3      c
      4      c
      5      c
      dtype: category
      Categories (2, object): ['b', 'c']
  
      >>> s.cat.set_categories([1, 2, 3], rename=True)  # doctest: +SKIP
      0    1
      1    2
      2    2
      3    3
      4    3
      5    3
      dtype: category
      Categories (3, int64): [1, 2, 3]
  
      >>> s.cat.set_categories([1, 2, 3], rename=True, ordered=True)  # doctest: +SKIP
      0    1
      1    2
      2    2
      3    3
      4    3
      5    3
      dtype: category
      Categories (3, int64): [1 < 2 < 3]
      """
      from pyspark.pandas.frame import DataFrame
  
      if not is_list_like(new_categories):
          raise TypeError(
              "Parameter 'new_categories' must be list-like, was '{}'".format(
                  new_categories
              )
          )
  
      if ordered is None:
          ordered = self.ordered
  
      new_dtype = CategoricalDtype(new_categories, ordered=ordered)
      scol = self._data.spark.column
  
      if rename:
          new_scol = (
              F.when(
                  scol >= len(new_categories),
                  F.lit(-1).cast(self._data.spark.data_type),
              )
              .otherwise(scol)
              .alias(self._data._internal.data_spark_column_names[0])
          )
  
          internal = self._data._psdf._internal.with_new_spark_column(
              self._data._column_label,
              new_scol,
              field=self._data._internal.data_fields[0].copy(
                  dtype=new_dtype
              ),
          )
  
          return (
              DataFrame(internal)
              ._psser_for(self._data._column_label)
              .copy()
          )
      else:
          return self._data.astype(new_dtype)
  
imports: from typing import Any, Callable, List, Optional, Union, TYPE_CHECKING, cast
  import pandas
  from pandas.api.types import CategoricalDtype, is_dict_like, is_list_like
  from pyspark.pandas.internal import InternalField
  from pyspark.pandas.data_type_ops.categorical_ops import _to_cat
  from pyspark.sql import functions
  from pyspark.sql.types import StructField
label_desc: Use image node_id 15 for calling the CategoricalAccessor obj's underlying member method code with example usage: obj.set_categories(new_categories, ordered, rename) and returns: DataFrame, self