code: def test_tensors_sort(ray_start_regular_shared):
      # Test Arrow table representation.
      t = pa.table(
          {
              "a": TensorArray(np.arange(32).reshape((2, 4, 4))),
              "b": [1, 2],
          }
      )
      ds = ray.data.from_arrow(t)
      sorted_ds = ds.sort(key="b", descending=True)
      sorted_arrs = [row["a"] for row in sorted_ds.take()]
      base = [row["a"] for row in ds.take()]
      np.testing.assert_raises(
          AssertionError,
          np.testing.assert_equal,
          sorted_arrs,
          base,
      )
      np.testing.assert_equal(
          sorted_arrs,
          sorted(base, key=lambda arr: -arr.min()),
      )
  
      # Test Pandas table representation.
      df = pd.DataFrame(
          {
              "a": TensorArray(np.arange(32).reshape((2, 4, 4))),
              "b": [1, 2],
          }
      )
      ds = ray.data.from_pandas(df)
      sorted_ds = ds.sort(key="b", descending=True)
      sorted_arrs = [np.asarray(row["a"]) for row in sorted_ds.take()]
      base = [np.asarray(row["a"]) for row in ds.take()]
      np.testing.assert_raises(
          AssertionError,
          np.testing.assert_equal,
          sorted_arrs,
          base,
      )
      np.testing.assert_equal(
          sorted_arrs,
          sorted(base, key=lambda arr: -arr.min()),
      )
  
imports: import time
  import numpy
  import pandas
  import pyarrow
  import pytest
  import ray
  from ray.air.util.tensor_extensions.utils import _create_possibly_ragged_ndarray
  from ray.data.block import BlockAccessor
  from ray.data.extensions.tensor_extension import ArrowTensorArray, ArrowTensorType, ArrowVariableShapedTensorArray, ArrowVariableShapedTensorType, TensorArray, TensorDtype
  from ray.data.tests.conftest import *
  from ray.data.tests.util import extract_values
  from ray.tests.conftest import *
label_desc: Use image node_id 5 for calling a global function with example usage: test_tensors_sort(ray_start_regular_shared) without return types