code: def sort_values(
      df: DataFrame,
      by: str | list[str],
      npartitions: int | Literal["auto"] | None = None,
      shuffle_method: str | None = None,
      ascending: bool | list[bool] = True,
      na_position: Literal["first"] | Literal["last"] = "last",
      upsample: float = 1.0,
      partition_size: float = 128e6,
      sort_function: Callable[[pd.DataFrame], pd.DataFrame]
      | None = None,
      sort_function_kwargs: Mapping[str, Any] | None = None,
  ) -> DataFrame:
      """See DataFrame.sort_values for docstring"""
      if na_position not in ("first", "last"):
          raise ValueError(
              "na_position must be either 'first' or 'last'"
          )
      if not isinstance(by, list):
          by = [by]
      if any(not isinstance(b, str) for b in by):
          raise NotImplementedError(
              "Dataframes only support sorting by named columns which must be passed as a "
              "string or a list of strings.\n"
              "You passed %s" % str(by)
          )
  
      sort_kwargs = {
          "by": by,
          "ascending": ascending,
          "na_position": na_position,
      }
      if sort_function is None:
          sort_function = M.sort_values
      if sort_function_kwargs is not None:
          sort_kwargs.update(sort_function_kwargs)
  
      if df.npartitions == 1:
          return df.map_partitions(sort_function, **sort_kwargs)
  
      if npartitions == "auto":
          warnings.warn(
              "`npartitions='auto'` is deprecated, either set it as an integer or leave as `None`.",
              FutureWarning,
              2,
          )
          repartition = True
          npartitions = max(100, df.npartitions)
      else:
          if npartitions is None:
              npartitions = df.npartitions
          repartition = False
  
      sort_by_col = df[by[0]]
  
      if not isinstance(ascending, bool):
          # support [True] as input
          if (
              isinstance(ascending, list)
              and len(ascending) == 1
              and isinstance(ascending[0], bool)
          ):
              ascending = ascending[0]
          else:
              raise NotImplementedError(
                  f"Dask currently only supports a single boolean for ascending. You passed {str(ascending)}"
              )
  
      divisions, _, _, presorted = _calculate_divisions(
          df,
          sort_by_col,
          repartition,
          npartitions,
          upsample,
          partition_size,
          ascending,
      )
  
      if len(divisions) == 2:
          return df.repartition(npartitions=1).map_partitions(
              sort_function, **sort_kwargs
          )
  
      if presorted and npartitions == df.npartitions:
          # divisions are in the right place
          return df.map_partitions(sort_function, **sort_kwargs)
  
      df = rearrange_by_divisions(
          df,
          by[0],
          divisions,
          shuffle_method=shuffle_method,
          ascending=ascending,
          na_position=na_position,
          duplicates=False,
      )
      df = df.map_partitions(sort_function, **sort_kwargs)
      return df
  
imports: from __future__ import annotations
  import contextlib
  import logging
  import math
  import shutil
  import tempfile
  import uuid
  import warnings
  from collections.abc import Callable, Mapping, Sequence
  from typing import Any, Literal
  import numpy
  import pandas
  import tlz
  from pandas.api.types import is_numeric_dtype
  from dask import config
  from dask.base import compute, compute_as_if_collection, is_dask_collection, tokenize
  from dask.dataframe import methods
  from dask.dataframe.core import DataFrame, Series, _deprecated_kwarg, _Frame, map_partitions, new_dd_object
  from dask.dataframe.dispatch import group_split_dispatch, hash_object_dispatch, partd_encode_dispatch
  from dask.dataframe.utils import UNKNOWN_CATEGORIES
  from dask.highlevelgraph import HighLevelGraph
  from dask.layers import ShuffleLayer, SimpleShuffleLayer
  from dask.sizeof import sizeof
  from dask.utils import M, digit, get_default_shuffle_method
label_desc: Use image node_id 2 for calling a global function with example usage: sort_values(df, by, npartitions, shuffle_method, ascending, na_position, upsample, partition_size, sort_function, sort_function_kwargs) and returns: df, df, df, df