def _sort_nmr_status_last(x: pd.Series) -> pd.Series:
  """
  A helper that sorts notes with NMR status last. This key function is used by sort_values
  to transform the ratingStatus to the ints in nmrSortLast
  """
  # We perform this complex sort because we need to make sure to count NMR notes for users that
  # have no CRH / CRNH notes. Explicitly filtering out these notes would lead to situations where
  # the user would end up without an enrollment state. We perform a key based sorting in descending
  # order. The nmrSortLast transforms CRH + CRNH notes to the beginning of the frame. The noteIdkey
  # (snowflake id) acts a secondary filter to make sure that we are checking for recent notes.
  nmrSortLast = DictCopyMissing(
    {
      c.needsMoreRatings: 0,
      c.currentlyRatedHelpful: 1,
      c.currentlyRatedNotHelpful: 1,
    }
  )
  return x.map(nmrSortLast)

  A helper that sorts notes with NMR status last. This key function is used by sort_values
  to transform the ratingStatus to the ints in nmrSortLast
  
sourcecode/scoring/contributor_state.py