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: Rename categories.
  
  Parameters
  ----------
  new_categories : list-like, dict-like or callable
  
      New categories which will replace old categories.
  
      * list-like: all items must be unique and the number of items in
        the new categories must match the existing number of categories.
  
      * dict-like: specifies a mapping from
        old categories to new. Categories not contained in the mapping
        are passed through and extra categories in the mapping are
        ignored.
  
      * callable : a callable that is called on all items in the old
        categories and whose return values comprise the new categories.
  
  Returns
  -------
  cat : Series
      Categorical with removed categories
  
  Raises
  ------
  ValueError
      If new categories are list-like and do not have the same number of
      items than the current categories or do not validate as categories
  
  See Also
  --------
  reorder_categories : Reorder categories.
  add_categories : Add new categories.
  remove_categories : Remove the specified categories.
  remove_unused_categories : Remove categories which are not used.
  set_categories : Set the categories to the specified ones.
  
  Examples
  --------
  >>> s = ps.Series(["a", "a", "b"], dtype="category")
  >>> s.cat.rename_categories([0, 1])  # doctest: +SKIP
  0    0
  1    0
  2    1
  dtype: category
  Categories (2, int64): [0, 1]
  
  For dict-like ``new_categories``, extra keys are ignored and
  categories not in the dictionary are passed through
  
  >>> s.cat.rename_categories({'a': 'A', 'c': 'C'})  # doctest: +SKIP
  0    A
  1    A
  2    b
  dtype: category
  Categories (2, object): ['A', 'b']
  
  You may also provide a callable to create the new categories
  
  >>> s.cat.rename_categories(lambda x: x.upper())  # doctest: +SKIP
  0    A
  1    A
  2    B
  dtype: category
  Categories (2, object): ['A', 'B']
docstr_tok: ["Rename","categories",".","Parameters","--","--","--","--","--","new_categories",":","list-like",",","dict-like","or","callable","New","categories","which","will","replace","old","categories",".","*","list-like",":","all","items","must","be","unique","and","the","number","of","items","in","the","new","categories","must","match","the","existing","number","of","categories",".","*","dict-like",":","specifies","a","mapping","from","old","categories","to","new",".","Categories","not","contained","in","the","mapping","are","passed","through","and","extra","categories","in","the","mapping","are","ignored",".","*","callable",":","a","callable","that","is","called","on","all","items","in","the","old","categories","and","whose","return","values","comprise","the","new","categories",".","Returns","--","--","--","-","cat",":","Series","Categorical","with","removed","categories","Raises","--","--","--","ValueError","If","new","categories","are","list-like","and","do","not","have","the","same","number","of","items","than","the","current","categories","or","do","not","validate","as","categories","See","Also","--","--","--","--","reorder_categories",":","Reorder","categories",".","add_categories",":","Add","new","categories",".","remove_categories",":","Remove","the","specified","categories",".","remove_unused_categories",":","Remove","categories","which","are","not","used",".","set_categories",":","Set","the","categories","to","the","specified","ones",".","Examples","--","--","--","--",">",">",">","s","=","ps.Series","(","[","``","a","''",",","``","a","''",",","``","b","''","]",",","dtype=","''","category","''",")",">",">",">","s.cat.rename_categories","(","[","0",",","1","]",")","#","doctest",":","+SKIP","0","0","1","0","2","1","dtype",":","category","Categories","(","2",",","int64",")",":","[","0",",","1","]","For","dict-like","``","new_categories","``",",","extra","keys","are","ignored","and","categories","not","in","the","dictionary","are","passed","through",">",">",">","s.cat.rename_categories","(","{","'","a","'",":","'","A","'",",","'","c","'",":","'","C","'","}",")","#","doctest",":","+SKIP","0","A","1","A","2","b","dtype",":","category","Categories","(","2",",","object",")",":","[","'","A","'",",","'","b","'","]","You","may","also","provide","a","callable","to","create","the","new","categories",">",">",">","s.cat.rename_categories","(","lambda","x",":","x.upper","(",")",")","#","doctest",":","+SKIP","0","A","1","A","2","B","dtype",":","category","Categories","(","2",",","object",")",":","[","'","A","'",",","'","B","'","]"]
code: def rename_categories(
      self, new_categories: Union[list, dict, Callable]
  ) -> Optional["ps.Series"]:
      """
      Rename categories.
  
      Parameters
      ----------
      new_categories : list-like, dict-like or callable
  
          New categories which will replace old categories.
  
          * list-like: all items must be unique and the number of items in
            the new categories must match the existing number of categories.
  
          * dict-like: specifies a mapping from
            old categories to new. Categories not contained in the mapping
            are passed through and extra categories in the mapping are
            ignored.
  
          * callable : a callable that is called on all items in the old
            categories and whose return values comprise the new categories.
  
      Returns
      -------
      cat : Series
          Categorical with removed categories
  
      Raises
      ------
      ValueError
          If new categories are list-like and do not have the same number of
          items than the current categories or do not validate as categories
  
      See Also
      --------
      reorder_categories : Reorder categories.
      add_categories : Add new categories.
      remove_categories : Remove the specified categories.
      remove_unused_categories : Remove categories which are not used.
      set_categories : Set the categories to the specified ones.
  
      Examples
      --------
      >>> s = ps.Series(["a", "a", "b"], dtype="category")
      >>> s.cat.rename_categories([0, 1])  # doctest: +SKIP
      0    0
      1    0
      2    1
      dtype: category
      Categories (2, int64): [0, 1]
  
      For dict-like ``new_categories``, extra keys are ignored and
      categories not in the dictionary are passed through
  
      >>> s.cat.rename_categories({'a': 'A', 'c': 'C'})  # doctest: +SKIP
      0    A
      1    A
      2    b
      dtype: category
      Categories (2, object): ['A', 'b']
  
      You may also provide a callable to create the new categories
  
      >>> s.cat.rename_categories(lambda x: x.upper())  # doctest: +SKIP
      0    A
      1    A
      2    B
      dtype: category
      Categories (2, object): ['A', 'B']
      """
      from pyspark.pandas.frame import DataFrame
  
      if is_dict_like(new_categories):
          categories = [
              cast(dict, new_categories).get(item, item)
              for item in self.categories
          ]
      elif callable(new_categories):
          categories = [
              new_categories(item) for item in self.categories
          ]
      elif is_list_like(new_categories):
          if len(self.categories) != len(new_categories):
              raise ValueError(
                  "new categories need to have the same number of items as the old categories!"
              )
          categories = cast(list, new_categories)
      else:
          raise TypeError(
              "new_categories must be list-like, dict-like or callable."
          )
  
      internal = self._data._psdf._internal.with_new_spark_column(
          self._data._column_label,
          self._data.spark.column,
          field=self._data._internal.data_fields[0].copy(
              dtype=CategoricalDtype(
                  categories=categories, ordered=self.ordered
              )
          ),
      )
  
      return (
          DataFrame(internal)
          ._psser_for(self._data._column_label)
          .copy()
      )
  
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 13 for calling the CategoricalAccessor obj's underlying member method code with example usage: obj.rename_categories(new_categories) and returns: DataFrame