class_docstr: Base class for all discrete scales
  
  Parameters
  ----------
  {superclass_parameters}
  limits : array_like, default=None
      Limits of the scale. For scales that deal with
      categoricals, these may be a subset or superset of
      the categories. Data values that are not in the limits
      will be treated as missing data and represented with
      the `na_value`.
  drop : bool, default=True
      Whether to drop unused categories from
      the scale
  na_translate : bool, default=True
      If `True` translate missing values and show them.
      If `False` remove missing values. Default value is
      `True`
  na_value : object
      If `na_translate=True`, what aesthetic value should be
      assigned to the missing values. This parameter does not
      apply to position scales where `nan` is always placed
      on the right.
class_docstr_tok: ["Base","class","for","all","discrete","scales","Parameters","--","--","--","--","--","{","superclass_parameters","}","limits",":","array_like",",","default=None","Limits","of","the","scale",".","For","scales","that","deal","with","categoricals",",","these","may","be","a","subset","or","superset","of","the","categories",".","Data","values","that","are","not","in","the","limits","will","be","treated","as","missing","data","and","represented","with","the","`","na_value","`",".","drop",":","bool",",","default=True","Whether","to","drop","unused","categories","from","the","scale","na_translate",":","bool",",","default=True","If","`","True","`","translate","missing","values","and","show","them",".","If","`","False","`","remove","missing","values",".","Default","value","is","`","True","`","na_value",":","object","If","`","na_translate=True","`",",","what","aesthetic","value","should","be","assigned","to","the","missing","values",".","This","parameter","does","not","apply","to","position","scales","where","`","nan","`","is","always","placed","on","the","right","."]
docstr: Map values in x to a palette
docstr_tok: ["Map","values","in","x","to","a","palette"]
code: def map(
      self, x, limits: Optional[ScaleDiscreteLimits] = None
  ) -> Sequence[Any]:
      """
      Map values in x to a palette
      """
      if limits is None:
          limits = self.limits
  
      n = sum(~pd.isna(list(limits)))
      pal = self.palette(n)
      if isinstance(pal, dict):
          # manual palette with specific assignments
          pal_match = []
          for val in x:
              try:
                  pal_match.append(pal[val])
              except KeyError:
                  pal_match.append(self.na_value)
      else:
          if not isinstance(pal, np.ndarray):
              pal = np.asarray(pal, dtype=object)
          idx = np.asarray(match(x, limits))
          try:
              pal_match = [pal[i] if i >= 0 else None for i in idx]
          except IndexError:
              # Deal with missing data
              # - Insert NaN where there is no match
              pal = np.hstack((pal.astype(object), np.nan))
              idx = np.clip(idx, 0, len(pal) - 1)
              pal_match = list(pal[idx])
  
      if self.na_translate:
          bool_pal_match = pd.isna(pal_match)
          if len(bool_pal_match.shape) > 1:
              # linetypes take tuples, these return 2d
              bool_pal_match = bool_pal_match.any(axis=1)
          bool_idx = pd.isna(x) | bool_pal_match
          if bool_idx.any():
              pal_match = [
                  x if i else self.na_value
                  for x, i in zip(pal_match, ~bool_idx)
              ]
  
      return pal_match
  
imports: from __future__ import annotations
  import typing
  import numpy
  import pandas
  from mizani.bounds import expand_range_distinct
  from .._utils import match
  from ..doctools import document
  from ..iapi import range_view, scale_view
  from ._expand import expand_range
  from .range import RangeDiscrete
  from .scale import scale
label_desc: Use image node_id 9 for calling the scale_discrete obj's underlying member method code with example usage: obj.map(x, limits) and returns: pal_match