class_docstr: Accessor object for categorical properties of the Series values.
  
  Examples
  --------
  >>> s.cat.categories  # doctest: +SKIP
  
  Notes
  -----
  Attributes that depend only on metadata are eager
  
  * categories
  * ordered
  
  Attributes depending on the entire dataset are lazy
  
  * codes
  * ...
  
  So `df.a.cat.categories` <=> `df.a._meta.cat.categories`
  So `df.a.cat.codes` <=> `df.a.map_partitions(lambda x: x.cat.codes)`
docstr: Removes categories which are not used
  
  Notes
  -----
  This method requires a full scan of the data to compute the
  unique values, which can be expensive.
docstr_tok: ["Removes","categories","which","are","not","used","Notes","--","--","-","This","method","requires","a","full","scan","of","the","data","to","compute","the","unique","values",",","which","can","be","expensive","."]
code: def remove_unused_categories(self):
      """
      Removes categories which are not used
  
      Notes
      -----
      This method requires a full scan of the data to compute the
      unique values, which can be expensive.
      """
      # get the set of used categories
      present = self._series.dropna().unique()
      present = pd.Index(present.compute())
  
      if isinstance(self._series._meta, pd.CategoricalIndex):
          meta_cat = self._series._meta
      else:
          meta_cat = self._series._meta.cat
  
      # Reorder to keep cat:code relationship, filtering unused (-1)
      ordered, mask = present.reindex(meta_cat.categories)
      if mask is None:
          # PANDAS-23963: old and new categories match.
          return self._series
  
      new_categories = ordered[mask != -1]
      meta = meta_cat.set_categories(
          new_categories, ordered=meta_cat.ordered
      )
      return self._series.map_partitions(
          self._delegate_method,
          "cat",
          "set_categories",
          (),
          {"new_categories": new_categories},
          meta=meta,
          token="cat-set_categories",
      )
  
imports: from __future__ import annotations
  from collections import defaultdict
  from numbers import Integral
  import pandas
  from pandas.api.types import is_scalar
  from tlz import partition_all
  from dask.base import compute_as_if_collection, tokenize
  from dask.dataframe import methods
  from dask.dataframe.accessor import Accessor
  from dask.dataframe.dispatch import categorical_dtype, categorical_dtype_dispatch, is_categorical_dtype
  from dask.dataframe.utils import AttributeNotImplementedError, clear_known_categories, has_known_categories
  from dask.highlevelgraph import HighLevelGraph
label_desc: Use image node_id 7 for calling the CategoricalAccessor obj's underlying member method code with example usage: obj.remove_unused_categories() and returns: self, self