code: def test_sort_values_key_casts_to_categorical(self, ordered):
      # https://github.com/pandas-dev/pandas/issues/36383
      categories = ["c", "b", "a"]
      df = DataFrame({"x": [1, 1, 1], "y": ["a", "b", "c"]})
  
      def sorter(key):
          if key.name == "y":
              return pd.Series(
                  Categorical(
                      key, categories=categories, ordered=ordered
                  )
              )
          return key
  
      result = df.sort_values(by=["x", "y"], key=sorter)
      expected = DataFrame(
          {"x": [1, 1, 1], "y": ["c", "b", "a"]},
          index=pd.Index([2, 1, 0]),
      )
  
      tm.assert_frame_equal(result, expected)
  
imports: import numpy
  import pytest
  import pandas
  from pandas import Categorical, DataFrame, NaT, Timestamp, date_range
  import pandas._testing
  from pandas.util.version import Version
label_desc: Use image node_id 10 for calling the TestDataFrameSortKey obj's underlying member method code with example usage: obj.test_sort_values_key_casts_to_categorical(ordered) and returns: key, pd